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:
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:
2. Select List under Choose layout dropdown and click on Advanced mode.
3. Add below JSON code in code editor and click on Save:
{
"$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
Above JSON is also available in PnP List Formatting Repository at: Highlight Selected List Item Rows.
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
LikeLiked by 1 person
I don’t think currently it is possible using SharePoint JSON form formatting.
LikeLike
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
LikeLike