A little help please! I created a SharePoint list with company contacts and I want in column 'length of service' the numbers 5, 10, 15, 20 etc. years to be marked a different color, for example red.
-
Are you using SharePoint Online modern experience list?Ganesh Sanap - MVP– Ganesh Sanap - MVP2023-10-23 12:44:35 +00:00Commented Oct 23, 2023 at 12:44
-
Please accept my below response as an answer as it helped you and it will help others with similar question to find the correct answer easily.Ganesh Sanap - MVP– Ganesh Sanap - MVP2023-10-23 16:43:21 +00:00Commented Oct 23, 2023 at 16:43
1 Answer
If you are using SharePoint online modern experience list and your "Length Of Service" column is of type "Number", you can use SharePoint column JSON formatting like:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"style": {
"font-weight": "=if(@currentField == 5 || @currentField == 10 || @currentField == 15 || @currentField == 20, 'bold', '')",
"color": "=if(@currentField == 5 || @currentField == 10 || @currentField == 15 || @currentField == 20, 'red', '')"
}
}
OR:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "[$LengthOfService]",
"style": {
"font-weight": "=if([$LengthOfService] == 5 || [$LengthOfService] == 10 || [$LengthOfService] == 15 || [$LengthOfService] == 20, 'bold', '')",
"color": "=if([$LengthOfService] == 5 || [$LengthOfService] == 10 || [$LengthOfService] == 15 || [$LengthOfService] == 20, 'red', '')"
}
}
Where [$LengthOfService] is the internal name of your number column. You can get the exact internal name of your column by following this article: How to find the Internal name of columns in SharePoint Online?.
OR
If you want to show colored number for all numbers which are multiples of 5, use:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "[$LengthOfService]",
"style": {
"font-weight": "=if([$LengthOfService] % 5 == 0, 'bold', '')",
"color": "=if([$LengthOfService] % 5 == 0, 'red', '')"
}
}
Output:
Microsoft official documentation and steps to apply JSON formatting to SharePoint list columns: Use column formatting to customize SharePoint
