SOLVED

SP Online List Formatting Cell Colour

Contributor

I have a simple list that contains column months and totals. See below:

 

t1.png

 

If any cell is greater than £0 I would like to change the background colour of that cell to red.

 

How can I achieve this?

7 Replies

@jonboylib Try using below JSON, it should work for number columns: 

 

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "div",
    "style": {
        "background-color": "=if(@currentField > 0, 'red', '')",
        "color": "white"
    },
    "txtContent": "@currentField"
}

 

 This JSON adds background color of cell as red. You can change the style as per your requirements.


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

@ganeshsanap Thanks, where do I add this JSON?

 

Also, I assume I don't have to add this to every row in my list?

You add the JSON to columns where you want this formatting. Select the drop down next to column -> Column settings -> format this column -> Select Advanced mode -> Paste the JSON @ganeshsanap provided. Do this for each column you want to add formatting to.
best response confirmed by jonboylib (Contributor)
Solution

@Bharath Arja Thanks.

 

So, it's not possible to apply this styling to a complete list? If I have 50 columns I need to do this 50 times, manually?

@jonboylib Yes, you have to add the JSON manually to all the list columns where you want to apply the formatting.

 

There is a way to update the JSON for each column using PowerShell. But, you must have at least basic experience with PowerShell to loop through list columns & add JSON to required columns. If you are using few columns only, I will suggest to do this manually.

 

Follow Microsoft official documentation for more information: Column formatting 


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

@jonboylib If you want to do this using PowerShell, refer below article:

 

SharePoint Online: Apply Column Format using PowerShell 


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

@jonboylib I think you have marked the wrong response as best response accidentally. :lol: