SharePoint: Highlight selected list item rows using JSON formatting

SharePoint: Highlight selected list item rows using JSON formatting

You can use JSON formatting in SharePoint to customize the display of columns and views in SharePoint online lists and Microsoft Lists.

Microsoft recently introduced @isSelected token in JSON formatting which helps us to determine if a list item is selected in list view or not.

The @isSelected token returns true when the list item is selected and false when the list item is not selected in list view:

@isSelected operator in SharePoint online and Microsoft Lists JSON Formatting
@isSelected operator in SharePoint JSON Formatting

Follow below steps to highlight selected list items in list view using SharePoint JSON formatting:

1. Go to SharePoint list, click on Switch view options dropdown and select Format current view:

JSON view formatting in SharePoint online/Microsoft Lists
JSON view formatting in SharePoint

2. Select List under Choose layout dropdown and click on Advanced mode.

3. Add below JSON code in code editor and click on Save:

Highlight selected list item row using JSON formatting in SharePoint online or Microsoft Lists
SharePoint JSON view formatting pane
{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json",
    "additionalRowClass": "=if(@isSelected, 'ms-bgColor-themePrimary ms-fontColor-white', '')"
}

Here we have used additionalRowClass property in JSON view formatting which applies one or more classes to the entire list row depending on the value of one or more fields in the row.

Output

Highlight selected list item rows using JSON formatting in SharePoint online or Microsoft Lists
Highlighted selected list item rows using JSON formatting in SharePoint

Above JSON is also available in PnP List Formatting Repository at: Highlight Selected List Item Rows.

Learn more

15 thoughts on “SharePoint: Highlight selected list item rows using JSON formatting

  1. Hello, nice work! I will certainly use it. I have a question for you. I would like to do something similar in the header formatting is form view. I would like to change the background color header if multiple records are selected. Any idea how to do that?

    Thank you

    Liked by 1 person

      1. Hello, I found a way to do it, but it’s not 100% perfect.

        You need to make the Title field mandatory, use a formula to check if it is empty and highlight the background color of the header if it is (I tried with other fields, but it only works with the Title field for whatever reason).

        If you select two or more items, it will highlight, but also when you create a new field (that’s why I’m saying it’s not perfect, but it is still pretty useful).

        Formula: “background-color”: “=if([$Title] == ”, ‘yellow’)

        Thank you

        Like

Leave a comment