Microsoft Lists column formatting

Microsoft Lists column formatting

In this SharePoint Online tutorial, we will see, sharepoint column formatting examples and sharepoint column formatting json examples.

We will see, how to do column formatting in a modern list in SharePoint Online Office 365. As we know Microsoft provided many new features on the SharePoint modern page, this is one of the good features in SharePoint Online modern lists.

We cant see this feature in SharePoint classic page.

SharePoint column formatting

SharePoint Column formatting does not affect data in lists or libraries. It changes the display of lists/libraries with the various colors, icons, font effect, etc. For this, we have to construct a JSON object to describes the elements that are displayed in the browser.

Complete SharePoint Training Course Just for $199 (Just for Today)

Read: SharePoint modern list view customization example

SharePoint column formatting examples

Let us see an example on SharePoint Online modern list column formatting.

Step 1: Log in to the SharePoint Online Office 365 site -> Go to Site Contents -> Create a list as per the below screenshot.

Microsoft Lists column formatting
sharepoint modern list column formatting

Step 2: Next click on any column in the SharePoint Online list and go to Column settings -> Format this column

Microsoft Lists column formatting
sharepoint column formatting examples

Step 3: Once you click on Format this column, you will get default background colors to set in your list column.

Microsoft Lists column formatting
sharepoint online modern list column formatting

Step 4: You can choose any other colors as per the requirement and next click on the Save button.

Microsoft Lists column formatting
sharepoint online modern list column formatting examples

Step 5: This is the view of my SharePoint Online list after column formatting.

Microsoft Lists column formatting
sharepoint column formatting examples

Step 6: The same steps I have applied for the status column where you can set the color as per the list status value.

Microsoft Lists column formatting
sharepoint column formatting json examples

Step 7: The below is the screenshot of my SharePoint Online list column where I change the colors as per the status value.

Microsoft Lists column formatting
sharepoint jsom column formatting

Step 8: Below is the final list after I applied the colors in the SharePoint Online list view. We can also apply the condition using code.

Microsoft Lists column formatting
sharepoint modern list column formatting examples

This one simple example we saw how to work with sharepoint column formatting.

Read: SharePoint jslink Examples

SharePoint column formatting json examples

Let us see a few examples of sharepoint column formatting JSON examples and I have taken mostly from GitHub.

Microsoft also allows us to customize columns in SharePoint lists and libraries by using column formatting with JSON. By using JSON we can format text, date, people, number and choices field, etc SharePoint list column types.

Now, let us see a few SharePoint column formatting JSON examples.

For this example, we created a list having the title, StartDate, TotalNo.of days, Assigned To, Status column. When we entered some data initially by default list will show you like this.

Microsoft Lists column formatting
sharepoint column formatting

Example-1: SharePoint column formatting json Title Column

For this first, we have to click on the Title field. then go to the Column setting. Select Format this column. Then go to Advanced mode. Now just put JSON code.

Microsoft Lists column formatting
Title Column Format, with JSON

To preview your formatting, click on Preview. For save, select Save. By Switch to design mode, you can reset your display to default mode.

In this above example, you can clearly see how the title column format. The simplest way to formatting a column is to place the value inside the

element. Here are the codes:

{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "txtContent": "@currentField" }

Example-2: SharePoint column formatting json Number

This example will show you using conditional formatting, how a number column is formatted with JSON. when the value of the current field is less than or equal to 10 then it will highlight the value of the field. And it will be normal when the value is greater than 10.

similarly go to advance mode. Apply JSON there. The field will be come like this:

Microsoft Lists column formatting
sharepoint column formatting json number field

Follow this below code for formatting a number column using Conditional statement:

{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "attributes": { "class": "=if(@currentField <= 10,'sp-field-severity--warning', '')" }, "children": [ { "elmType": "span", "style": { "display": "inline-block", "padding": "0 4px" }, "attributes": { "iconName": "=if(@currentField <= 10,'Error', '')" } }, { "elmType": "span", "txtContent": "@currentField" } ] }

Example-3: SharePoint column formatting json choice column example

You can also apply conditional formatting on the SharePoint choice column. Here we use the status as the choice column.

In this example, You can see the choices of the status column are formatted according to the values. Here we apply the CSS classes like sp-field-severitygood, sp-field-severitylow, sp-field-severitywarning, sp-field-severitySeverewarning for completed, On Going, Started, Not Started respectively.

You can apply this example or you can put your own value according to your requirement. This will help you to distinguish the severity of different level with icons.

Similarly, go to advance mode. Apply JSON there. The field will be come like this:

Microsoft Lists column formatting
SharePoint Choice Column Format with JSON

Follow this below code for formatting a Choice column using Conditional JSON statement:

{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "attributes": { "class": "=if(@currentField == 'Completed', 'sp-field-severity--good', if(@currentField == 'On Going', 'sp-field-severity--low', if(@currentField == 'Started', 'sp-field-severity--warning', 'sp-field-severity--severeWarning'))) + ' ms-fontColor-neutralSecondary'" }, "children": [ { "elmType": "span", "style": { "display": "inline-block", "padding": "0 4px" }, "attributes": { "iconName": "=if(@currentField == 'Completed', 'CheckMark', if(@currentField == 'On Going', 'Forward', if(@currentField == 'Started', 'Error', 'Warning')))" } }, { "elmType": "span", "txtContent": "@currentField" } ] }

Example-4: SharePoint column formatting json date examples

In this example, it will show you how the color of Start Date will change after applying of JSON.

*The color will be changed if the start date is not the same or before the current date then it will be formatted as color otherwise, it displays as normal. Here we use @now for resolving the current date/time, and use color code to displaying the previous date/time.(i.e, todays date 4/23/2021).

For this formatting , go to advance mode. Then save it. Then the field will be come like this:

Microsoft Lists column formatting
sharepoint column formatting json date exampleDate column format with JSON

Follow this below code for formatting a Choice column using Conditional JSON statement:

{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "debugMode": true, "txtContent": "@currentField", "style": { "color": "=if([$StartDate] <= @now, '#DE3163', '')" } }

In above example, color of date field will changed when it is same or previous date of current date. You can modify the color code, as your requirement.

Example-5: SharePoint column formatting json person column

In this formatting, we can able to add a button in the people field. This example also helps you to render a quick action that links to this field.

After applying JSON, the Assign To(people type column) will converted like below screen:

Microsoft Lists column formatting
People Column Format with JSON

Follow this below code for formatting a people column using Conditional JSON statement.

{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "children": [ { "elmType": "span", "style": { "padding-right": "8px" }, "txtContent": "@currentField.title" }, { "elmType": "a", "attributes": { "iconName": "Mail", "class": "sp-field-quickActions", "href": { "operator": "+", "operands": [ "mailto:", "@currentField.email", "?subject=Task status&body=Hey, how is your task coming along?.\r\n---\r\n", "@currentField.title", "\r\nClick this link for more info. http://contoso.sharepoint.com/sites/ConferencePrep/Tasks/Prep/DispForm.aspx?ID=", "[$ID]" ] } } } ] }

In the above example, the

element work as a parent element. It contains two child elements, one is element, which contains the persons details, and another element is contained the quick actions for email sending(mailto).

Now You can check the differences between column formatting with JSON and default column in SharePoint List.

Microsoft Lists column formatting
sharepoint column formatting json examples

This is another example of how SharePoint Online modern list column formatting works.

You may like following SharePoint tutorials:

  • PowerShell SharePoint list operations
  • SharePoint list operations using rest api
  • SharePoint list delete title column
  • Create SharePoint list view
  • How to create a calculated column in SharePoint List or Library
  • Microsoft Flow Example Save tweets that include specific hashtag to a SharePoint list
  • SPFx Bind dropdown list from SharePoint list using PnP
  • Display SharePoint list data in jQuery data table using Rest API
  • SharePoint list permissions

I hope this SharePoint tutorial explains, how to implement column formatting in SharePoint Online modern list, sharepoint column formatting json examples, and sharepoint column formatting examples.

Rajkiran is currently working as a SharePoint Consultant in India . Rajkiran having 7+ years of experience in Microsoft Technologies such as SharePoint 2019/2016/2013/2010, MOSS 2007,WSS 3.0, Migration, Asp.Net, C#.Net, Sql Server, Ajax, jQuery etc.He is C#Corner MVP (2 Times).