1

I have created a modern list in SPO with JSON conditional formatting on the row and view levels.

One conditional formatting snippet I've added hides the cell text (row level) based on the current user. But I would like to also hide the column header text as well and cannot figure out how to do this.

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField",
  "style": {
    "display": "=if(@me == '[email protected]','','none')"
  }
}

Similarly, I would like to format the column header to have a line break in case the title is long. This could be done with on-premise using CSS but again I have not found a way to do this in JSON. The actual column text can be JSON formatted to break but I can't do it at the column heading level. Simply adding a BR tag or \n\r (or its HTML-encoded equivalent) doesn't do anything.

Any insight would be welcome.

1

1 Answer 1

1

This is a known limitation of JSON formatting in SharePoint.

You cannot format the column headers using JSON formatting in SharePoint online.

7
  • Thank you Ganesh - so is there an option aside from JSON that can be used to format the column headers? May 7, 2021 at 19:28
  • Do you want to hide the column for one specific user or are there any other conditions based on those you want to hide the column? Can you please explain your requirements, maybe based on that I can suggest a workaround if any. May 9, 2021 at 13:22
  • Also you can check this view formatting sample for custom column headers. You can use the conditions like you are already using in view formatting. But it's drawback is you loose all the SharePoint default functionalities like sorting/filtering, context menu, etc. May 9, 2021 at 13:26
  • 1
    Thank you very much for your help Ganesh. I will poll our users regarding the classic experience. I wish the API would allow us access to the column header itself in the same way we can access the individual column elements (using indexes). May 13, 2021 at 14:40
  • 1
    @GaneshSanap-MVP: link to custom header page is broken, new link is github.com/pnp/List-Formatting/tree/master/view-samples/… Feb 12 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.