Skip to content

Commit 82a3a0b

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 8f91993 + 21cfa0f commit 82a3a0b

File tree

2 files changed

+168
-59
lines changed

2 files changed

+168
-59
lines changed

docs/declarative-customization/column-formatting.md

Lines changed: 163 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,18 @@ This example demonstrates an alternate syntax to express a conditional expressio
222222
}
223223
```
224224

225+
Here's the same sample from above, using the Excel-style expression syntax:
226+
```JSON
227+
{
228+
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
229+
"elmType": "div",
230+
"txtContent": "@currentField",
231+
"style": {
232+
"color": "=if([$DueDate] <= @now + 86400000, '#ff0000', '')"
233+
}
234+
}
235+
```
236+
225237
<br/>
226238

227239

@@ -256,6 +268,18 @@ To compare a date/time field value against another date constant, use the `Date(
256268
}
257269
```
258270

271+
Here's the same sample from above, using the Excel-style expression syntax:
272+
```JSON
273+
{
274+
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
275+
"elmType": "div",
276+
"txtContent": "@currentField",
277+
"style": {
278+
"color": "=if([$DueDate] <= Date('3/22/2017'), '#ff0000', '')"
279+
}
280+
}
281+
```
282+
259283
## Create clickable actions
260284

261285
You can use column formatting to provide hyperlinks that go to other webpages, or start custom functionality. This functionality is limited to static links that can be paramaterized with values from fields in the list. You can't use column formatting to output links to protocols other than `http://`, `https://`, or `mailto:`.
@@ -333,18 +357,28 @@ The following image shows a number column formatted as a data bar.
333357

334358
![Effort list with number list items shown as bars](../images/sp-columnformatting-databars.png)
335359

336-
This example applies `background-color` and `border-top` styles to create a data bar visualization of `@currentField`, which is a number field. The bars are sized differently for different values based on the way the `width` attribute is set - it's set to `100%` when the value is greater than 95, and `(@currentField * 100 / 95)%` otherwise. To fit this example to your number column, you can adjust the boundary condition (`20`) to match the maximum anticipated value inside the field, and change the equation to specify how much the bar should grow depending on the value inside the field.
360+
This example applies `background-color` and `border-top` styles to create a data bar visualization of `@currentField`, which is a number field. The bars are sized differently for different values based on the way the `width` attribute is set - it's set to `100%` when the value is greater than 20, and `(@currentField * 5)%` otherwise. To fit this example to your number column, you can adjust the boundary condition (`20`) to match the maximum anticipated value inside the field, and change the equation to specify how much the bar should grow depending on the value inside the field.
337361

338362
```JSON
339363
{
340364
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
341365
"elmType": "div",
342-
"txtContent": "@currentField",
366+
"children": [
367+
{
368+
"elmType": "span",
369+
"txtContent": "@currentField",
370+
"style": {
371+
"padding-left": "8px",
372+
"white-space": "nowrap"
373+
}
374+
}
375+
],
343376
"attributes": {
344377
"class": "sp-field-dataBars"
345378
},
346379
"style": {
347-
"width": "=if(@currentField > 95, '100%', toString(@currentField * 100 / 95) + '%')"
380+
"padding": "0",
381+
"width": "=if(@currentField >= 20, '100%', (@currentField * 5) + '%')"
348382
}
349383
}
350384
```
@@ -416,6 +450,27 @@ This example relies on two number fields, `Before` and `After`, for which the va
416450
}
417451
```
418452

453+
Here's the same sample from above, using the Excel-style expression syntax:
454+
```JSON
455+
{
456+
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
457+
"elmType": "div",
458+
"children": [
459+
{
460+
"elmType": "span",
461+
"attributes": {
462+
"class": "=if([$After] > [$Before], 'sp-field-trending--up', 'sp-field-trending--down')",
463+
"iconName": "=if([$After] > [$Before], 'SortUp', "=if([$After] < [$Before], 'SortDown', ''))"
464+
}
465+
},
466+
{
467+
"elmType": "span",
468+
"txtContent": "[$After]"
469+
}
470+
]
471+
}
472+
```
473+
419474
## Create a button to launch a Flow
420475

421476
The following screenshot shows a list with a Flow button added to the Action column:
@@ -432,33 +487,33 @@ To use the sample below, you must substitute the ID of the Flow you want to run.
432487

433488
```JSON
434489
{
435-
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
436-
"elmType": "span",
437-
"style": {
438-
"color": "#0078d7"
439-
},
440-
"children": [
441-
{
442-
"elmType": "span",
443-
"attributes": {
444-
"iconName": "Flow"
445-
}
446-
},
447-
{
448-
"elmType": "button",
449-
"style": {
450-
"border": "none",
451-
"background-color": "transparent",
452-
"color": "#0078d7",
453-
"cursor": "pointer"
454-
},
455-
"txtContent": "Send to Manager",
456-
"customRowAction": {
457-
"action": "executeFlow",
458-
"actionParams": "{\"id\": \"183bedd4-6f2b-4264-855c-9dc7617b4dbe\"}"
459-
}
460-
}
461-
]
490+
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
491+
"elmType": "span",
492+
"style": {
493+
"color": "#0078d7"
494+
},
495+
"children": [
496+
{
497+
"elmType": "span",
498+
"attributes": {
499+
"iconName": "Flow"
500+
}
501+
},
502+
{
503+
"elmType": "button",
504+
"style": {
505+
"border": "none",
506+
"background-color": "transparent",
507+
"color": "#0078d7",
508+
"cursor": "pointer"
509+
},
510+
"txtContent": "Send to Manager",
511+
"customRowAction": {
512+
"action": "executeFlow",
513+
"actionParams": "{\"id\": \"183bedd4-6f2b-4264-855c-9dc7617b4dbe\"}"
514+
}
515+
}
516+
]
462517
}
463518
```
464519

@@ -746,20 +801,35 @@ The following example shows the value of a style object. In this example, two st
746801
```JSON
747802
{
748803
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
749-
"padding": "4px",
750-
"background-color": {
751-
"operator": "?",
752-
"operands": [
753-
{
754-
"operator": "<",
755-
"operands": [
756-
"@currentField",
757-
40
758-
]
759-
},
760-
"#ff0000",
761-
"#00ff00"
762-
]
804+
"elmType": "div",
805+
"style": {
806+
"padding": "4px",
807+
"background-color": {
808+
"operator": "?",
809+
"operands": [
810+
{
811+
"operator": "<",
812+
"operands": [
813+
"@currentField",
814+
40
815+
]
816+
},
817+
"#ff0000",
818+
"#00ff00"
819+
]
820+
}
821+
}
822+
}
823+
```
824+
825+
Here's the same sample from above, using the Excel-style expression syntax:
826+
```JSON
827+
{
828+
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
829+
"elmType": "div",
830+
"style": {
831+
"padding": "4px",
832+
"background-color": "=if(@currentField < 40, '#ff0000', '#00ff00')"
763833
}
764834
}
765835
```
@@ -783,9 +853,9 @@ Any other attribute name will result in an error. Attribute values can either be
783853

784854
```JSON
785855
{
786-
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
787-
"target": "_blank",
788-
"href": "='http://finance.yahoo.com/quote/' + @currentField"
856+
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
857+
"target": "_blank",
858+
"href": "='http://finance.yahoo.com/quote/' + @currentField"
789859
}
790860
```
791861

@@ -799,11 +869,13 @@ An optional property that is meant for debugging. It outputs error messages and
799869

800870
### Expressions
801871

802-
Values for `txtContent`, style properties, and attribute properties can be expressed as expressions, so that they are evaluated at runtime based on the context of the current field (or row). Expression objects can be nested to contain other Expression objects.
872+
Values for `txtContent`, style properties, and attribute properties can be expressed as expressions, so that they are evaluated at runtime based on the context of the current field (or row). Expression objects can be nested to contain other Expression objects.
873+
874+
Expressions can be written using Excel-style expressions in SharePoint Online, or by using Abstract Syntax Tree expressions in SharePoint Online and SharePoint 2019.
803875

804876
#### Excel-style expressions
805877

806-
All Excel-style expressions begin with an equal (`=`) sign.
878+
All Excel-style expressions begin with an equal (`=`) sign. This style of expression is only available in SharePoint Online (not SharePoint 2019).
807879

808880
This simple conditional expression evaluates to `none` if `@me` is not equal to `[$Author.email]`, and evaluates to \`\` otherwise:
809881
```JSON
@@ -896,6 +968,7 @@ Operators specify the type of operation to perform. The following operators are
896968
- toLowerCase
897969
- join
898970
- length
971+
- abs
899972

900973
**Binary arthmetic operators** - The following are the standard arithmetic binary operators that expect two operands:
901974

@@ -936,10 +1009,13 @@ Operators specify the type of operation to perform. The following operators are
9361009
- **toLocaleTimeString()**: returns a language sensitive representation of just the time portion of a date
9371010
- `"txtContent":"=toLocaleTimeString(@now)"` results vary based on user's locale, but en-us looks like _"1:22:24 PM"_
9381011

939-
- **toLowerCase**: returns the value converted to lower case (only works on strings)
1012+
- **toLowerCase**: returns the value converted to lower case (only works on strings) - _Only available in SharePoint Online_
9401013
- `"txtContent":"=toLowerCase('DogFood')"` results in _"dogfood"_
9411014

942-
- **length**: returns the number of items in an array (multi-select person or choice field), for all other value types it returns 1 when true and 0 when false. It does NOT provide the length of a string value.
1015+
- **abs**: returns the absolute value for a given number - _Only available in SharePoint Online_
1016+
- `"txtContent":"=abs(-45)"` results in _45_
1017+
1018+
- **length**: returns the number of items in an array (multi-select person or choice field), for all other value types it returns 1 when true and 0 when false. It does NOT provide the length of a string value. - _Only available in SharePoint Online_
9431019
- `"txtContent":"=length(@currentField)"` might result in _2_ if there are 2 selected values
9441020
- `"txtContent":"=length('Some Text')"` results in _1_
9451021
- `"txtContent":"=length('')"` results in _0_
@@ -948,13 +1024,13 @@ Operators specify the type of operation to perform. The following operators are
9481024

9491025
**Binary operators** - The following are operators that expect two operands:
9501026

951-
- **indexOf**: takes 2 operands. The first is the text you would like to search within, the second is the text you would like to search for. Returns the index value of the first occurence of the search term within the string. Indexes start at 0. If the search term is not found within the text, -1 is returned. This operator is case-sensitive.
1027+
- **indexOf**: takes 2 operands. The first is the text you would like to search within, the second is the text you would like to search for. Returns the index value of the first occurence of the search term within the string. Indexes start at 0. If the search term is not found within the text, -1 is returned. This operator is case-sensitive. - _Only available in SharePoint Online_
9521028
- `"txtContent": "=indexOf('DogFood', 'Dog')"` results in _0_
9531029
- `"txtContent": "=indexOf('DogFood', 'F')"` results in _3_
9541030
- `"txtContent": "=indexOf('DogFood', 'Cat')"` results in _-1_
9551031
- `"txtContent": "=indexOf('DogFood', 'f')"` results in _-1_
9561032

957-
- **join**: takes 2 operands. The first is an array (multi-select person or choice field) and the second is the separating string. Returns a string concatenation of the array values separated by the separating string.
1033+
- **join**: takes 2 operands. The first is an array (multi-select person or choice field) and the second is the separating string. Returns a string concatenation of the array values separated by the separating string. - _Only available in SharePoint Online_
9581034
- `"txtContent": "=join(@currentField, ', ')"` might result in _"Apple, Orange, Cherry"_ (depending on the selected values)
9591035
- `"txtContent": "=join(@currentField.title, '|')"` might result in _"Chris Kent|Vesa Juvonen|Jeff Teper"_ (depending on the selected persons)
9601036

@@ -1016,6 +1092,15 @@ For example, the following JSON will display the current field (assuming it's a
10161092
}
10171093
```
10181094

1095+
Here's the same sample from above, using the Excel-style expression syntax:
1096+
```JSON
1097+
{
1098+
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
1099+
"elmType": "div",
1100+
"txtContent": "=toLocaleString(@currentField)"
1101+
}
1102+
```
1103+
10191104
**Lookup fields**
10201105

10211106
The lookup field object has the following properties (with example values):
@@ -1085,7 +1170,7 @@ If the value of a field is an object, the object's properties can be accessed. F
10851170

10861171
#### "@currentWeb"
10871172

1088-
This will evaluate to the absolute url for the site. This is equivalent to the `webAbsoluteUrl` value within the page context.
1173+
This will evaluate to the absolute url for the site. This is equivalent to the `webAbsoluteUrl` value within the page context. This value is only available in SharePoint Online.
10891174

10901175
#### "@me"
10911176

@@ -1117,10 +1202,34 @@ This field can be used to display the current user's email address, but more lik
11171202
}
11181203
```
11191204

1205+
Here's the same sample from above, using the Excel-style expression syntax:
1206+
```JSON
1207+
{
1208+
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
1209+
"elmType": "div",
1210+
"txtContent": "@currentField.title",
1211+
"style": {
1212+
"color": "=if(@me == @currentField.email, 'red', 'blue')"
1213+
}
1214+
}
1215+
```
1216+
11201217
#### "@now"
11211218

11221219
This will evaluate to the current date and time.
11231220

1221+
#### "@rowIndex"
1222+
1223+
This will evaluate to the rendered index of a row within a view. This value is based on render position and will remain consistent based on position even as views are sorted and filtered. Indexes start at 0. This value is only available in SharePoint Online.
1224+
1225+
Here's an example of using the value within a view format to apply alternating styles to rows:
1226+
```JSON
1227+
{
1228+
"$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
1229+
"additionalRowClass": "=if(@rowIndex % 2 == 0,'ms-bgColor-themeLighter ms-bgColor-themeLight--hover','')"
1230+
}
1231+
```
1232+
11241233
#### "@window.innerHeight"
11251234

11261235
This will evaluate to a number equal to the height of the browser window (in pixels) when the list was rendered.

docs/spfx/web-parts/basics/add-an-external-library.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ By default, the web part bundler automatically includes any library that is a de
2626
```
2727

2828
> [!NOTE]
29-
> Because you're using TypeScript, you need typings for the package you add. This is essential when you are writing code because TypeScript is just a superset of JavaScript. All the TypeScript code is still converted to JavaScript code when you compile. You can search for and find typings by using **npm**, for example: `npm install @types/{package} --save`
29+
> Because you're using TypeScript, you need typings for the package you add. This is essential when you are writing code because TypeScript is just a superset of JavaScript. All the TypeScript code is still converted to JavaScript code when you compile. You can search for and find typings by using **npm**, for example: `npm install @types/{package} --save-dev`
3030
3131
3. Create a file in the your web part's folder called `validator.d.ts` and add the following:
3232

@@ -69,7 +69,7 @@ In this example, you will share the [marked](https://www.npmjs.com/package/marke
6969
2. Download the typings:
7070
7171
```sh
72-
npm install @types/marked --save
72+
npm install @types/marked --save-dev
7373
```
7474
7575
3. Edit the **config/config.json**, and add an entry to the **externals** map. This is what tells the bundler to put this in a separate file. This prevents the bundler from bundling this library:
@@ -101,7 +101,7 @@ In this example, you will load jQuery from CDN. You don't need to install the np
101101
1. Install the typings for jQuery:
102102

103103
```sh
104-
npm install --save @types/jquery
104+
npm install --save-dev @types/jquery
105105
```
106106

107107
2. Update the `config.json` in the `config` folder to load jQuery from CDN. Add an entry to the `externals` field:
@@ -279,13 +279,13 @@ Loading SharePoint JSOM is essentially the same scenario as loading non-AMD scri
279279
1. Install typings for Microsoft Ajax, which is a dependency for JSOM typings:
280280
281281
```sh
282-
npm install @types/microsoft-ajax --save
282+
npm install @types/microsoft-ajax --save-dev
283283
```
284284
285285
2. Install typings for the JSOM:
286286
287287
```sh
288-
npm install @types/sharepoint --save
288+
npm install @types/sharepoint --save-dev
289289
```
290290
291291
3. Add entries to the `config.json`:

0 commit comments

Comments
 (0)