Formatting All Columns in Microsoft or Sharepoint Lists

Brass Contributor

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.

1 Reply

@CSU_Scott If you want to apply JSON formatting to whole list view, use view formatting.

 

Also, note:

  1. You cannot apply JSON formatting to all columns in list automatically / manually from UI/browser
  2. You can use PowerShell to apply JSON formatting for multiple columns, check: How to export or backup column formatting JSON values? 
  3. Some of the columns in SharePoint like person or group, lookup, image columns are complex columns. So, only using "@currentField" will not work in this case
  4. If you are facing any bug while applying valid JSON formatting to any column, raise support ticket with Microsoft: Get M365 help - online support 

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.