|
1 | 1 | ---
|
2 | 2 | title: Use column formatting to customize SharePoint
|
3 | 3 | 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 |
5 | 5 | localization_priority: Priority
|
6 | 6 | ---
|
7 | 7 |
|
@@ -51,7 +51,7 @@ To preview the formatting, select **Preview**. To commit your changes, select **
|
51 | 51 | 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).
|
52 | 52 |
|
53 | 53 | > [!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. |
55 | 55 |
|
56 | 56 |
|
57 | 57 | ## Display field values (basic)
|
@@ -816,7 +816,101 @@ Both the example uses defaultHoverField
|
816 | 816 | ```
|
817 | 817 |
|
818 | 818 |
|
| 819 | +## Column formatter reference |
819 | 820 |
|
| 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 | +``` |
820 | 914 |
|
821 | 915 | ## Supported column types
|
822 | 916 |
|
@@ -880,24 +974,13 @@ You can use predefined icons from Office UI Fabric. For details, see the [Fabric
|
880 | 974 |
|
881 | 975 | ## Creating custom JSON
|
882 | 976 |
|
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. |
888 | 978 |
|
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. |
898 | 981 |
|
899 | 982 | > [!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. |
901 | 984 |
|
902 | 985 | > [!TIP]
|
903 | 986 | > 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
|
1876 | 1959 | }
|
1877 | 1960 | ```
|
1878 | 1961 |
|
| 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 | + |
1879 | 1972 | ## See also
|
1880 | 1973 |
|
1881 | 1974 | - [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