Column formatting In SharePoint Online

About column formatting
Microsoft introduced SharePoint Column Formatting within SharePoint Lists and Libraries for SharePoint Online. 

So, I was delighted to see that Microsoft have introduced a way to add SharePoint column formatting within the browser for #SharePointlist and #libraries. You can pretty much see your column values displayed in any way you want to, without hacking away in SharePoint Designer. But is it easy to accomplish as a Citizen Developer?

Here We have the document library which have 4 folders and accordingly add a value in number field.
Follow the below steps to open the area to add custom Json to format the field in Modern SharePoint Document Library or List.

Click on 1 , 2 and 3 in a sequence

How to create a Json string to format field?
1. Download Visual Studio Code. It’s free and fast to download.
2. In Visual Studio Code, create a new file, and save the empty file with a .json file extension.
3. Paste the following lines of code into your empty file.

{
“$schema”: “https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json”
}
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.
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.
3. Add below json text in Json Area

{
“$schema”: “https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json”,
“elmType”: “div”,
“style”: {
“padding”: “4px”,
“background-color”: {
“operator”: “?”,
“operands”: [
{
“operator”: “<“,
“operands”: [
“@currentField”,
2
]
},
“#ff0000”,
“#00ff00”
]
}
}
}

It defines if Current Field Value is less than 2 the field color will be red and value is greater than 2 then field color will be green
Field looks as below

I will come soon with more details of Json string.

Happy Coding 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.