Modern SharePoint list columns can be customized using a simple rendering template built with a JSON syntax.  This is the successor of using conditional formatting in SharePoint Designer.  When using column formatting, you can replace the default style for how a column is rendered with your own rendering logic.  In this article we demonstrate a stop light status indicator column that will display a Red, Yellow, or Green icon based on the value of a choice column. To format a Yes/No column with check marks see our other article Check Mark SharePoint Modern List Column Format.

First, we create a new column of type choice with available options of Green, Yellow, or Red.

To display the column formatting pane use the drop-down for the column you want to format and select Column settings -> Format this column.

This will open the Format column pane to the right-side of the window.  You simply paste your JSON column formatting into this panel and then click Preview or Save to see the column rendering in action.

Paste the JSON code shown below into the Format column pane to render a SharePoint Yes/No column with a check mark when the value of the column is equal to Yes.

{
    "$schema": "http://columnformatting.sharepointpnp.com/columnFormattingSchema.json",
    "debugMode": true,
    "elmType": "div",
    "children": [
        {
            "elmType": "span",
            "style": {
                "width": "14px",
                "height": "14px",
                "border-radius": "14px",
                "background-color": {
                    "operator": "?",
                    "operands": [
                        {
                            "operator": "==",
                            "operands": [
                                {
                                    "operator": "toString()",
                                    "operands": [
                                        "@currentField"
                                    ]
                                },
                                "Green"
                            ]
                        },
                        "#2dc937",
                        {
                            "operator": "?",
                            "operands":[
                                {
                                    "operator": "==",
                                    "operands": [
                                        {
                                            "operator": "toString()",
                                            "operands": [
                                                "@currentField"
                                            ]
                                        },
                                        "Yellow"
                                    ]
                                },
                                "#e7b416",
                                {
                                    "operator": "?",
                                    "operands":[
                                        {
                                            "operator": "==",
                                            "operands": [
                                                {
                                                    "operator": "toString()",
                                                    "operands": [
                                                        "@currentField"
                                                    ]
                                                },
                                                "Red"
                                            ]
                                        },
                                        "#cc3232",
                                        ""
                                    ]
                                }
                            ]
                        }
                    ]
                }
            }
        }
    ]
}

For more information, see the Microsoft document about using JSON custom formatting Use column formatting to customize SharePoint.

This column formatting is also available from the PnP github repo SharePoint/sp-dev-column-formatting.

Share
This

Post a comment