Column Formatting In SharePoint Online - No Coding

Scenario

 
You have a list in SharePoint with generic columns like Status, Due Date, Assigned To, Actual Hours, etc. You might want to highlight the data from each of these columns depending upon its value.
 

Solution

 
Well, back there in SP 2010/2013, you would have done this using XSLT, SharePoint Designer, JSLink, Content editor web part, JavaScript, and many other ways.
 
For SharePoint Online, it is just a configuration exactly like an MS Excel file.
 
Depending upon the type of the field, the configuration is provided in SharePoint Online.
 

No Code solution

 
If the column type is Yes/No, Choice, or Date, then you just need to configure the colors; no need of JSON code.
 

JSON code solution

 
For all other column types like Single line of text, Person and Group, you need to construct the JSON for formatting but that is also readily available at Microsoft documentation. You just need to update the logic as per your need.
 

How to format Yes/No, Choice, Date columns

 
Open your SharePoint Online List >> Select the Yes/No column which you want to format >> Column Settings >> Format this Column
 
Column Formatting In SharePoint Online - No Coding
 
For the choice of Yes/No and Date columns you will find the default template already present. You need to select that template >> Preview the result >> hit Save button.
 
Column Formatting In SharePoint Online - No Coding
 
If you want to modify the default colors applied >> Click on Edit Template >> as shown below you will get option to select color for each of the values.
 
Column Formatting In SharePoint Online - No Coding
 
Those are the default color shades provided in design view to select >> choose as per your wise for both the values >> Once saved that’s how the formatting looks.
 
Column Formatting In SharePoint Online - No Coding
 
Let’s look at how Choice columns formatting options look  >> Select any choice column >> Column setting >> Format this column
 
Column Formatting In SharePoint Online - No Coding
 
And once you click on Edit Template that’s how it appears with all the choice values >> Choose the color for each of the choice options and hit Save/Apply.
 
Column Formatting In SharePoint Online - No Coding
 
Let’s see what’s there if you click on Advanced mode in the above screen. Just to highlight, those are two important locations in JSON which tells you what class is being applied for a particular value. These classes are already present in default CSS which is part of Office UI Fabric.
 
Ok, so how do you put your own class or your own background color in this JSON? We will see in a while.
 
Column Formatting In SharePoint Online - No Coding
 
For the Date/Time column below, three categorizations are provided for formatting by default. You can  modify this JSON using Advanced mode to fulfill your own requirement
 
Before Today, Today, After Today
 
Column Formatting In SharePoint Online - No Coding
 

Formatting using JSON

 
In the above steps, we saw how we can use default templates and format the column. Yet, what if we want to apply our own color/style – how and what to modify in already generated JSON?
 
Example - I wanted to apply different background colors to Yes/No values than the one which was applied with the default template.
 
So, click on Advanced mode. Use the JSON provided below and update the color code/values as per your need. In the default JSON, the class name is being provided conditionally, so I have applied the style conditionally.
 
Column Formatting In SharePoint Online - No Coding
  1. {  
  2.   "elmType""div",  
  3.   "style": {  
  4.     "padding""0 4px",  
  5.     "color""white",  
  6.     "background-color": {  
  7.         "operator"":",  
  8.       "operands": [  
  9.         {  
  10.           "operator""==",  
  11.           "operands": [  
  12.             "@currentField",  
  13.             true  
  14.           ]  
  15.         },  
  16.         "Red",  
  17.         {  
  18.           "operator"":",  
  19.           "operands": [  
  20.             {  
  21.               "operator""==",  
  22.               "operands": [  
  23.                 "@currentField",  
  24.                 false  
  25.               ]  
  26.             },  
  27.             "Green",  
  28.             ""  
  29.           ]  
  30.         }  
  31.       ]  
  32.     }  
  33.   },  
  34.   "attributes": {  
  35.   },  
  36.   "txtContent""=if(@currentField==true,'Yes',if(@currentField==false,'No',''))"  
  37. }  
Going further, you can show icons as well depending upon the values. Use the below JSON for formatting your Choice/Text column with icons. You need to modify the choice or Text values as per your scenario. Choose the classes from the provided options.
 
Column Formatting In SharePoint Online - No Coding
  1. {  
  2.   "$schema""https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",  
  3.   "elmType""div",  
  4.   "attributes": {  
  5.     "class""=if(@currentField == 'Done', 'sp-field-severity--good', if(@currentField == 'In Progress', 'sp-field-severity--low', if(@currentField == 'On Hold', 'sp-field-severity--warning', if(@currentField == 'Not Started', 'sp-field-severity--severeWarning', 'sp-field-severity--blocked')))) + ' ms-fontColor-neutralSecondary'"  
  6.   },  
  7.   "children": [  
  8.     {  
  9.       "elmType""span",  
  10.       "style": {  
  11.         "display""inline-block",  
  12.         "padding""0 4px"  
  13.       },  
  14.       "attributes": {  
  15.         "iconName""=if(@currentField == 'Done', 'CheckMark', if(@currentField == 'In Progress', 'Forward', if(@currentField == 'On Hold', 'Error', if(@currentField == 'Not Started', 'Warning', 'ErrorBadge'))))"  
  16.       }  
  17.     },  
  18.     {  
  19.       "elmType""span",  
  20.       "txtContent""@currentField"  
  21.     }  
  22.   ]  
  23. }  
Below are some example of classes and how they format your column values. Try using them in your list view. It will put a nice impact on the end users.
 
Column Formatting In SharePoint Online - No Coding
 
Hopefully, this article has helped you to understand the column formatting options in SharePoint online. Refer to Microsoft documentation for more details.