Forum Discussion
StuartReeves
Jan 19, 2022Copper Contributor
JSON conditional formatting for mileages
Hello! I am trying to code some conditional formatting for a mileage field in sharepoint. I would like the field: - to be green with a tick if the mileage in > 30000 - to be white with an arro...
- Jan 19, 2022
StuartReeves have a go with the following JSON:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "attributes": { "class": "=if(@currentField >= 3000, 'sp-field-severity--good', if(@currentField < 3000 && @currentField >= 1000, 'sp-field-severity--low',if(@currentField < 1000 && @currentField >= 100, 'sp-field-severity--warning','sp-field-severity--blocked')))" }, "children": [ { "elmType": "span", "style": { "display": "inline-block", "padding": "0 4px" }, "attributes": { "iconName": "=if(@currentField >= 3000, 'CheckMark', if(@currentField < 3000 && @currentField >= 1000, 'Forward',if(@currentField < 1000 && @currentField >= 100, 'Error','ErrorBadge')))" } }, { "elmType": "span", "txtContent": "@currentField" } ] }which results in:
Rob
Los Gallardos
Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)
RobElliott
Jan 19, 2022Silver Contributor
StuartReeves have a go with the following JSON:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"attributes": {
"class": "=if(@currentField >= 3000, 'sp-field-severity--good', if(@currentField < 3000 && @currentField >= 1000, 'sp-field-severity--low',if(@currentField < 1000 && @currentField >= 100, 'sp-field-severity--warning','sp-field-severity--blocked')))"
},
"children": [
{
"elmType": "span",
"style": {
"display": "inline-block",
"padding": "0 4px"
},
"attributes": {
"iconName": "=if(@currentField >= 3000, 'CheckMark', if(@currentField < 3000 && @currentField >= 1000, 'Forward',if(@currentField < 1000 && @currentField >= 100, 'Error','ErrorBadge')))"
}
},
{
"elmType": "span",
"txtContent": "@currentField"
}
]
}
which results in:
Rob
Los Gallardos
Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)
- StuartReevesJan 19, 2022Copper ContributorRob,
You are a god send! That worked perfectly! Thank you so much!
Stuart