Forum Discussion
John Duckett
Jan 16, 2019Copper Contributor
Conditional formatting using JSON
I have tried to customise a column using JSON script lifted from this site https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting#apply-conditional-formattin...
John Warner
Jan 16, 2019Iron Contributor
Have you checked to make sure the field is a number field?
- John DuckettJan 16, 2019Copper ContributorJohn thank you for the reply, apologies I was a bit vague in the initial description. Is the textual fields I'm looking at doing formatting on - a RAG status that I wasn't to colour red / amber/ green depending on the value in my RAG column.
- John WarnerJan 16, 2019Iron ContributorThe copy/paste JSON should work out of the box, no need for anything to be turned on, at least as far as SharePoint Online. You may have to adjust the code depending on values within your column. For instance change the value of YOUR_RAG_STATUS_VALUE in the code below to each possible RAG value for your field :
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"attributes": {
"class": "=if(@currentField == 'YOUR_RAG_STATUS_VALUE', 'sp-field-severity--good', if(@currentField == 'YOUR_RAG_STATUS_VALUE', 'sp-field-severity--low', if(@currentField == 'YOUR_RAG_STATUS_VALUE', 'sp-field-severity--warning', if(@currentField == 'YOUR_RAG_STATUS_VALUE', 'sp-field-severity--severeWarning', 'sp-field-severity--blocked')))) + ' ms-fontColor-neutralSecondary'"
}
}- John DuckettJan 16, 2019Copper ContributorThat's what I thought, but nothing happens so then I wondered if it was spacing between the lines (I know literally nothing about JSON so was guessing)
Then I wondered whether it was because it wasn't a standard column, but one I had created.