Oct 20 2022 08:00 AM
I wanted a generic way to apply formatting to all columns of a list without going column by column and editing each. Currently, I am doing that but substituted the field name for @currentField. This works, but does generate an error.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"style": {
"box-sizing": "border-box",
"padding": "0 2px",
"overflow": "hidden",
"text-overflow": "ellipsis"
},
"attributes": {
"class": {
"operator": ":",
"operands": [
{
"operator": "==",
"operands": [
"@currentField",
"Working Remote"
]
},
"sp-css-backgroundColor-BgMintGreen sp-css-borderColor-MintGreenFont sp-css-color-MintGreenFont sp-field-bold",
{
"operator": ":",
"operands": [
{
"operator": "==",
"operands": [
"@currentField",
"Vacation Unavailable"
]
},
"sp-css-backgroundColor-BgDustRose sp-css-borderColor-DustRoseFont sp-css-color-DustRoseFont sp-field-bold",
{
"operator": ":",
"operands": [
{
"operator": "==",
"operands": [
"@currentField",
"Vacation Available"
]
},
"sp-css-backgroundColor-BgGold sp-css-borderColor-GoldFont sp-css-color-GoldFont sp-field-bold",
{
"operator": ":",
"operands": [
{
"operator": "==",
"operands": [
"@currentField",
"Working Campus"
]
},
"sp-css-backgroundColor-BgMintGreen sp-css-borderColor-MintGreenFont sp-field-fontSizeSmall sp-css-color-MintGreenFont sp-field-bold",
""
]
}
]
}
]
}
]
}
},
"txtContent": "@currentField"
}
Saving the column format generates the following error, which I am not sure is detrimental as the formatting does work as expected. I think the Id variable at the end is blank and kicks off the error.
{"d": {"CustomFormatter": "{\"$schema\":\"https:\u002F\u002Fdeveloper.microsoft.com\u002Fjson-schemas\u002Fsp\u002Fv2\u002Fcolumn-formatting.schema.json\",\"elmType\":\"div\",\"style\":{\"box-sizing\":\"border-box\",\"padding\":\"0 2px\",\"overflow\":\"hidden\",\"text-overflow\":\"ellipsis\"},\"attributes\":{\"class\":{\"operator\":\":\",\"operands\":[{\"operator\":\"==\",\"operands\":[\"@currentField\",\"Working Remote\"]},\"sp-css-backgroundColor-BgMintGreen sp-css-borderColor-MintGreenFont sp-css-color-MintGreenFont sp-field-bold\",{\"operator\":\":\",\"operands\":[{\"operator\":\"==\",\"operands\":[\"@currentField\",\"Vacation Unavailable\"]},\"sp-css-backgroundColor-BgDustRose sp-css-borderColor-DustRoseFont sp-css-color-DustRoseFont sp-field-bold\",{\"operator\":\":\",\"operands\":[{\"operator\":\"==\",\"operands\":[\"@currentField\",\"Vacation Available\"]},\"sp-css-backgroundColor-BgGold sp-css-borderColor-GoldFont sp-css-color-GoldFont sp-field-bold\",{\"operator\":\":\",\"operands\":[{\"operator\":\"==\",\"operands\":[\"@currentField\",\"Working Campus\"]},\"sp-css-backgroundColor-BgMintGreen sp-css-borderColor-MintGreenFont sp-field-fontSizeSmall sp-css-color-MintGreenFont sp-field-bold\",\"\"]}]}]}]}},\"txtContent\":\"@currentField\"}", "Id": ""}}
1. Is there a way to apply this type of formatting to the entire list so that all columns are formatter?
2. Is there a way to correct my JSON formatting as to not generate the error? Can I form it more properly?
Thanks in advance.
CSU_Scott
New List and SharePoint user/admin.
Oct 20 2022 10:56 AM
@CSU_Scott If you want to apply JSON formatting to whole list view, use view formatting.
Also, note:
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.