Conditional Formatting for SharePoint List & Library Columns with JSON

Want to create a SharePoint list with dynamic formatting? In our tutorial today, we will learn how to apply formatting to fields in a column in your list based on the value in the field, using JSON.


Why would you want to color code columns in a SharePoint list? Well, in my example, I have a team of project managers who are providing project information via a centralized list. We want our department heads to view project metrics in visual way.


With JSON, we will color the fields dynamically, using a choice field's values to determine whether the field displays as green, white, yellow, orange, or red. The code provided also includes a visual indicator icon. Decision makers can quickly scan a list, easily spotting projects that are experiencing issues, no matter how the list is sorted or filtered.


To follow along with this guide:

Full Control: You should have full control or owner level permission for the list or library where you want to format the columns.

Choice Column: The list or library should have a choice column that you will use to determine column formatting. In my example, I am using a choice column called Status with 5 options.

Notepad: You'll want to use Notepad or your favorite script editing application in order to edit the JSON more easily. I use a very useful -AND FREE!- application called Notepad++ (Download).

Modern Experience: The list must be in the modern experience. JSON formatting does not display in classic experience.


STEP 1: Navigate to the list.


STEP 2: Create a new choice column.


STEP 3: Add options to the choice column.


STEP 4: Open Format Column pane. Click the choice column title menu, select column settings, select Format this column.


STEP 5: Customize JSON code if necessary (JSON code provided below).

  • You can replace the choice option names (highlighted below in green) with your own options, just make sure you match the capitalization - JSON is case sensitive.

  • You can replace the syntax @currentField if you want to reference a different column by using the syntax [$YourColumnName].

  • You can pick your own icons by replacing the icon names in the code (highlighted in blue). Microsoft Fabric UI icons and their names can be found here.

STEP 6: Paste the JSON code in the Format Column pane that appears.


STEP 7: Click Save.



{

"$schema": "http://columnformatting.sharepointpnp.com/columnFormattingSchema.json",

"elmType": "div",

"attributes": {

"class": {

"operator": "?",

"operands": [

{

"operator": "==",

"operands": [

"@currentField",

"No Issues"

]

},

"sp-field-severity--good",

{

"operator": "?",

"operands": [

{

"operator": "==",

"operands": [

"@currentField",

"Inactive"

]

},

"sp-field-severity--low",

{

"operator": "?",

"operands": [

{

"operator": "==",

"operands": [

"@currentField",

"Warning"

]

},

"sp-field-severity--warning",

{

"operator": "?",

"operands": [

{

"operator": "==",

"operands": [

"@currentField",

"In Review"

]

},

"sp-field-severity--severeWarning",

"sp-field-severity--blocked"

]

}

]

}

]

}

]

}

},

"children": [

{

"elmType": "span",

"style": {

"display": "inline-block",

"padding-left": "4px"

},

"attributes": {

"iconName": {

"operator": "?",

"operands": [

{

"operator": "==",

"operands": [

"@currentField",

"No Issues"

]

},

"CheckMark",

{

"operator": "?",

"operands": [

{

"operator": "==",

"operands": [

"@currentField",

"Inactive"

]

},

"Forward",

{

"operator": "?",

"operands": [

{

"operator": "==",

"operands": [

"@currentField",

"In Review"

]

},

"Error",

{

"operator": "?",

"operands": [

{

"operator": "==",

"operands": [

"@currentField",

"Warning"

]

},

"Warning",

"ErrorBadge"

]

}

]

}

]

}

]

}

}

},

{

"elmType": "span",

"txtContent": "@currentField",

"style": {

"padding-left": "10px",

"font-weight": "bold"

}

}

]

}

698 views

sme|SharePoint. Made easy.

 

Tampa, FL

856-857-7523

 

  • YouTube - SME
  • LinkedIn - SME
  • Twitter - SME

© 2018 by sme

Send us your feedback or suggest new content topics. We're listening.