Skip to content

Commit 9a66397

Browse files
thechriskentVesaJuvonen
authored andcommitted
Operator Additions (SharePoint#3399)
Added new operators and expanded operator section with explanations and examples
1 parent 43e6105 commit 9a66397

File tree

1 file changed

+55
-12
lines changed

1 file changed

+55
-12
lines changed

docs/declarative-customization/column-formatting.md

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -892,8 +892,12 @@ Operators specify the type of operation to perform. The following operators are
892892
- toLocaleString()
893893
- toLocaleDateString()
894894
- toLocaleTimeString()
895+
- indexOf
896+
- toLowerCase
897+
- join
898+
- length
895899

896-
**Binary operators** - The following are the standard arithmetic binary operators that expect two operands:
900+
**Binary arthmetic operators** - The following are the standard arithmetic binary operators that expect two operands:
897901

898902
- \+
899903
- \-
@@ -906,20 +910,59 @@ Operators specify the type of operation to perform. The following operators are
906910

907911
**Unary operators** - The following are standard unary operators that expect only one operand:
908912

909-
- toString()
910-
- Number()
911-
- Date()
912-
- cos
913-
- sin
914-
- toLocaleString()
915-
- toLocaleDateString()
916-
- toLocaleTimeString()
913+
- **toString()**: returns a string representing the object
914+
- `"txtContent": "=toString(45)"` results in _"45"_
915+
916+
- **Number()**: returns the numeric value, if the operand is not a number, NaN is returned
917+
- `"txtContent": "=Number('365')"` results in _365_
918+
- `"txtContent": "=Number('Wowee')"` results in _NaN_
919+
- `"txtContent": "=Number(Date('12/26/1981'))"` results in _378190800000_
920+
921+
- **Date()**: returns a datetime object from the parameter (converts strings or numbers to dates, sensitive to locale)
922+
- `"txtContent": "=Date('12/26/1981')"` results in _12/26/1981, 12:00:00 AM_
923+
924+
- **cos**: returns the cosine of the specified angle which should be specified in radians
925+
- `"txtContent": "=cos(5)"` results in _0.28366218546322625_
926+
927+
- **sin**: returns the sine of a number
928+
- `"txtContent": "=sin(90)"` results in _0.8939966636005579_
929+
930+
- **toLocaleString()**: returns a language sensitive representation of a date
931+
- `"txtContent":"=toLocaleString(@now)"` results vary based on user's locale, but en-us looks like _"2/5/2019, 1:22:24 PM"_
932+
933+
- **toLocaleDateString()**: returns a language sensitive representation of just the date portion of a date
934+
- `"txtContent":"=toLocaleDateString(@now)"` results vary based on user's locale, but en-us looks like _"2/5/2019"_
935+
936+
- **toLocaleTimeString()**: returns a language sensitive representation of just the time portion of a date
937+
- `"txtContent":"=toLocaleTimeString(@now)"` results vary based on user's locale, but en-us looks like _"1:22:24 PM"_
938+
939+
- **toLowerCase**: returns the value converted to lower case (only works on strings)
940+
- `"txtContent":"=toLowerCase('DogFood')"` results in _"dogfood"_
941+
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.
943+
- `"txtContent":"=length(@currentField)"` might result in _2_ if there are 2 selected values
944+
- `"txtContent":"=length('Some Text')"` results in _1_
945+
- `"txtContent":"=length('')"` results in _0_
946+
- `"txtContent":"=length(45)"` results in _1_
947+
- `"txtContent":"=length(0)"` results in _0_
948+
949+
**Binary operators** - The following are operators that expect two operands:
950+
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.
952+
- `"txtContent": "=indexOf('DogFood', 'Dog')"` results in _0_
953+
- `"txtContent": "=indexOf('DogFood', 'F')"` results in _3_
954+
- `"txtContent": "=indexOf('DogFood', 'Cat')"` results in _-1_
955+
- `"txtContent": "=indexOf('DogFood', 'f')"` results in _-1_
956+
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.
958+
- `"txtContent": "=join(@currentField, ', ')"` might result in _"Apple, Orange, Cherry"_ (depending on the selected values)
959+
- `"txtContent": "=join(@currentField.title, '|')"` might result in _"Chris Kent|Vesa Juvonen|Jeff Teper"_ (depending on the selected persons)
917960

918961
**Conditional operator** - The conditional operator is:
919962

920-
- ?
921-
922-
This is to achieve an expression equivalent to a ? b : c, where if the expression a evaluates to true, then the result is b, else the result is c.
963+
- **?**: Conditional operations written in Abstract Tree Syntax use `?` as the operator. This is to achieve an expression equivalent to a ? b : c, where if the expression a evaluates to true, then the result is b, else the result is c. For Excel style expressions you write these with an `if` statement. Regardless, there are 3 operands. The first is the condition to evaluate. The second is the result when the condition is true. The third is the result when the condition is false.
964+
- `"txtContent":"=if(4 < 5, 'yes', 'no')"` results in _"yes"_
965+
- `"txtContent":"=if(4 > 5, 'yes', 'no')"` results in _"no"_
923966

924967
### operands
925968

0 commit comments

Comments
 (0)