Skip to content

Commit 81a04c8

Browse files
authored
Custom formatter documentation update (SharePoint#6586)
Formatting pane experience updates View formatting pane pivot updates and terminology fixes columnFormatterReference support
1 parent 6d51c30 commit 81a04c8

7 files changed

+250
-158
lines changed

docs/declarative-customization/column-formatting.md

Lines changed: 110 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Use column formatting to customize SharePoint
33
description: Customize how fields in SharePoint lists and libraries are displayed by constructing a JSON object that describes the elements that are displayed when a field is included in a list view, and the styles to be applied to those elements.
4-
ms.date: 11/18/2020
4+
ms.date: 12/29/2020
55
localization_priority: Priority
66
---
77

@@ -51,7 +51,7 @@ To preview the formatting, select **Preview**. To commit your changes, select **
5151
The easiest way to use column formatting is to start from an example and edit it to apply to your specific field. The following sections contain examples that you can copy, paste, and edit for your scenarios. There are also several samples available in the [SharePoint/sp-dev-column-formatting repository](https://github.com/SharePoint/sp-dev-column-formatting).
5252

5353
> [!NOTE]
54-
> All examples in this document refer to the json schema used in SharePoint Online. To format columns on SharePoint 2019, please use `https://developer.microsoft.com/json-schemas/sp/v1/column-formatting.schema.json` as the schema.
54+
> All examples in this document refer to the JSON schema used in SharePoint Online. To format columns on SharePoint 2019, please use `https://developer.microsoft.com/json-schemas/sp/v1/column-formatting.schema.json` as the schema.
5555
5656

5757
## Display field values (basic)
@@ -816,7 +816,101 @@ Both the example uses defaultHoverField
816816
```
817817

818818

819+
## Column formatter reference
819820

821+
Users can refer to a column's formatter JSON inside another column/view formatter and use it along with other elements to build a custom column visualization. This can be done by using `columnFormatterReference` property.
822+
823+
The following image shows a list with a Gallery layout referencing the Category column formatter:
824+
<img src="../images/sp-columnformatting-formatter-reference-1.png" alt="Gallery layout referring Category column"/>
825+
826+
<img src="../images/sp-columnformatting-formatter-reference-2.png" alt="List layout with Category column formatted"/>
827+
828+
``` JSON
829+
{
830+
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/tile-formatting.schema.json",
831+
"height": 127,
832+
"width": 254,
833+
"hideSelection": false,
834+
"formatter": {
835+
"elmType": "div",
836+
"attributes": {
837+
"class": "sp-card-container"
838+
},
839+
"children": [
840+
{
841+
"elmType": "button",
842+
"attributes": {
843+
"class": "sp-card-defaultClickButton"
844+
},
845+
"customRowAction": {
846+
"action": "defaultClick"
847+
}
848+
},
849+
{
850+
"elmType": "div",
851+
"attributes": {
852+
"class": "ms-bgColor-white sp-css-borderColor-neutralLight sp-card-borderHighlight sp-card-subContainer"
853+
},
854+
"children": [
855+
{
856+
"elmType": "div",
857+
"attributes": {
858+
"class": "sp-card-displayColumnContainer"
859+
},
860+
"children": [
861+
{
862+
"elmType": "p",
863+
"attributes": {
864+
"class": "ms-fontColor-neutralSecondaryAlt sp-card-label"
865+
},
866+
"txtContent": "[!Title.DisplayName]"
867+
},
868+
{
869+
"elmType": "p",
870+
"attributes": {
871+
"title": "[$Title]",
872+
"class": "ms-fontColor-neutralPrimary sp-card-content sp-card-highlightedContent"
873+
},
874+
"txtContent": "=if ([$Title] == '', '–', [$Title])"
875+
}
876+
]
877+
},
878+
{
879+
"elmType": "div",
880+
"attributes": {
881+
"class": "sp-card-lastTextColumnContainer"
882+
},
883+
"children": [
884+
{
885+
"elmType": "p",
886+
"attributes": {
887+
"class": "ms-fontColor-neutralSecondaryAlt sp-card-label"
888+
},
889+
"txtContent": "[!Category.DisplayName]"
890+
},
891+
{
892+
"elmType": "div",
893+
"attributes": {
894+
"class": "sp-card-content"
895+
},
896+
"style": {
897+
"height": "32px",
898+
"font-size":"12px"
899+
},
900+
"children": [
901+
{
902+
"columnFormatterReference": "[$Category]"
903+
}
904+
]
905+
}
906+
]
907+
}
908+
]
909+
}
910+
]
911+
}
912+
}
913+
```
820914

821915
## Supported column types
822916

@@ -880,24 +974,13 @@ You can use predefined icons from Office UI Fabric. For details, see the [Fabric
880974

881975
## Creating custom JSON
882976

883-
Creating custom column formatting JSON from scratch is simple if you understand the schema. To create your own custom column formatting:
884-
885-
1. [Download Visual Studio Code](https://code.visualstudio.com/Download). It's free and fast to download.
886-
887-
2. In Visual Studio Code, create a new file, and save the empty file with a .json file extension.
977+
Creating custom column formatting JSON from scratch is simple if user understands the schema, Monaco Editor is integrated in the formatting pane with pre-filled JSON column schema reference to assist in creation of column formatting, Monaco editor has validation and autocomplete to help in crafting right JSON. User can start adding JSON after the first line that defines the schema ___location.
888978

889-
3. Paste the following lines of code into your empty file.
890-
891-
```JSON
892-
{
893-
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json"
894-
}
895-
```
896-
897-
You now have validation and autocomplete to create your JSON. You can start adding your JSON after the first line that defines the schema ___location.
979+
> [!TIP]
980+
> At any point, select **Ctrl**+**Space** for property/value suggestions.
898981
899982
> [!TIP]
900-
> At any point, select **Ctrl**+**Space** to have Visual Studio Code offer suggestions for properties and values. For more information, see [Editing JSON with Visual Studio Code](https://code.visualstudio.com/Docs/languages/json).
983+
> You can start from a HTML using [**formatter helper tool**](https://pnp.github.io/sp-dev-list-formatting/tools/), which can convert HTML and CSS into formatter JSON with inline styles.
901984
902985
> [!TIP]
903986
> SharePoint Patterns and Practices provides a free web part, [Column Formatter](https://github.com/SharePoint/sp-dev-solutions/blob/master/solutions/ColumnFormatter/docs/documentation/docs/getting-started.md), that can be used to edit and apply formats directly in the browser.
@@ -1876,6 +1959,16 @@ This also works with field name
18761959
}
18771960
```
18781961

1962+
#### columnFormatterReference
1963+
1964+
This will be replaced with the referenced column's formatter JSON. Multi level reference is not supported.
1965+
1966+
```JSON
1967+
{
1968+
"columnFormatterReference": "[$FieldName]"
1969+
}
1970+
```
1971+
18791972
## See also
18801973

18811974
- [Column formatting](https://support.office.com/article/Column-formatting-1f927342-2bed-4745-b727-ff8b7ff96b22?ui=en-US&rs=en-US&ad=US)

0 commit comments

Comments
 (0)