0
votes

I am trying to change the color of a column header in a view on a Sharepoint Online list, ideally using the JSON schema that Microsoft provides for formatting views.

I have found Microsoft's documentation which outlines a number of interesting examples, for example I can hide the column header altogether with "hideColumnHeader": true or I can change the color of group header, but there does not seem to be any documentation of how to change the background color for the column header itself.

https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/view-formatting

What I'm trying to achieve is very simple. I want to change the column header background color and font color, and have different colors for different columns like one can easily do in Excel:

Example of what I want the Sharepoint List view to look like

Is this possible using the JSON schema?

Thanks in advance for your time.

1

1 Answers

0
votes

I recently found and implemented this for row values, it may help for column headers also:

````  {

"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "txtContent": "@currentField", "style": { "color": "=if(@currentField == 'Purple 1', '#ffffff','')", "background-color": "=if(@currentField == 'Gold 1', '#D7AC11', if(@currentField == 'Gold 2', '#DBBA2F', if(@currentField == 'Gold 3', '#F1D531', if(@currentField == 'Aqua 1', '#008198', if(@currentField == 'Aqua 2', '#00bed8', if(@currentField == 'Aqua 3', '#75C7B9', if(@currentField == 'Green', '#84b638', if(@currentField == 'Grey 1', '#808285', if(@currentField == 'Grey 2', '#9d9fa2', if(@currentField == 'Grey 3', '#bcbec0', if(@currentField == 'Grey 4', '#e6e7e8', if(@currentField == 'Red', '#ca4e28', if(@currentField == 'Purple 1', '#492f92', if(@currentField == 'Purple 2', '#9c8dc3', '' ) ) ) )) ) ) ) ) )))))"

} }