SharePoint column formatting examples

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 can’t 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.

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.

sharepoint modern list 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

sharepoint column formatting examples
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.

sharepoint online modern list 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.

sharepoint online modern list column formatting examples
sharepoint online modern list column formatting examples

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

sharepoint column formatting examples
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.

sharepoint column formatting json examples
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.

sharepoint jsom 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.

sharepoint modern list column formatting examples
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.

sharepoint 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.

sharepoint column formatting examples
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 <div/> 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:

sharepoint column formatting json
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-severity–good, sp-field-severity–low, sp-field-severity–warning, sp-field-severity–Severewarning 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:

sharepoint column formatting json conditional choice column example
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, today’s date 4/23/2021).

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

sharepoint column formatting json date examples
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:

People Column JSONFormat
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 <div/> element work as a parent element. It contains two child elements, one is <span/> element, which contains the person’s details, and another <a/> 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.

sharepoint column formatting json examples
sharepoint column formatting json examples

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

You may like following SharePoint tutorials:

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.

  • >