0
votes

I am trying to do conditional formatting of a column in a sharepoint list. My need is fairly simple. The column is a "choice" type field - with 6 possible values. For each of these values, I would like the column to be shown in a specific color (m:n mapping, n

I tried using the recommended JSON code, it ended up being far too complicated because of the extreme amount of nesting.

1
Yes, depending on the version of SharePoint that your are using. Version (2013, 2016, etc)? SharePoint Online or On-Prem?Mike Smith - MCT - MVP
Thank you @MikeSmith-MCT-MVP. I am using SharePoint Onlinesachinsdesai
Sorry, I've got an easy solution, but it's blocked in SharePoint Online. (techtrainingnotes.blogspot.com/2018/01/…)Mike Smith - MCT - MVP

1 Answers

0
votes

If you use modern list in SharePoint online, we can use the OOTB formatting like below.

enter image description here

If you only want to color the text, the JSON formatting also easy.

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField",
  "style": {
    "color": "=if(@currentField == 'A', '#ff0000', if(@currentField=='B','#11ff00',if(@currentField=='C','#1111ff',if(@currentField=='D','#aa3344',if(@currentField=='E','#22aa44','#3344aa')))))"
  }
}

enter image description here

If you use the classic list view, we can use JSLINK to achieve it, the following article with code for your reference.

SharePoint list conditional formatting with JSLink