Back to view formats
View formattingSharePoint Online

Group by header color depending on item count

Group by header colors green when 5 items are grouped

Group by header color depending on item count formatting preview
Sample preview · View original image

Copy. Apply. Make it yours.

Get this format

1 definition

Review the requirements below, then paste this JSON into the matching formatting panel. Show me where.

Use your list's internal column names and replace any tenant-specific URLs or flow IDs. Formatting is presentation, not a way to secure data.

View formatting
Download JSON
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json",
  "groupProps": {
    "headerFormatter": {
      "elmType": "div",
      "style": {
        "padding": "4px 8px 5px 8px",
        "border-radius": "6px",
        "margin": "1px 4px 4px 1px",
        "background-color": "=if(@group.count == 1, 'Red',if(@group.count == 2, '#FF681E',if(@group.count == 3, '#FF980E',if(@group.count == 4, '#ffe40e','Green'))))"
      },
      "children": [
        {
          "elmType": "div",
          "txtContent": "=@group.count",
          "style": {
            "padding": "5px 5px 5px 5px",
            "color": "white",
            "font-weight": "500"
          }
        },
        {
          "elmType": "div",
          "txtContent": " of 5 ",
          "style": {
            "color": "white",
            "font-weight": "500"
          }
        }
      ]
    }
  }
}

From the contributor

How to use this sample

Summary

This is a sample of customizing the group header by showing a color code that changes depending on the amount of items in the group:

  • Less then 5 items shows the header as red, yellow, etc
  • Exactly 5 items shows the header as green

screenshot of the sample

The header will also show "x of 5", with x being the amount of items in the group.

View requirements

Group by a column of choice.

Sample

Solution Author(s)
group-header-color-itemcount.json Marijnsomers

Version history

Version Date Comments
1.0 February 20, 2023 Initial release

Disclaimer

THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.


Additional notes

  • None