List 365 view json - color group header based on condition

harry777 61 Reputation points
2021-08-08T09:57:33.503+00:00

I'm trying to write a Json for my view.

How can I make the background of groupby column header green if all items in Status column are Completed?

121393-image.png

I have the below code so far,

I have this logic:

count the number of times Completed appears for grouped project == @group Count then change the background of the header to green

{  
  
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json",  
  
  "groupProps": {  
  
    "headerFormatter": {  
  
      "elmType": "div",  
  
      "txtContent": "=@group.fieldData + ' (' + @group.count + ')'",  
  
      "style": {  
  
        "font-weight": "600"  
  
      },  
  
      "children": [  
  
        {  
  
          "elmType": "div",  
  
          "forEach": "project in @projectField",  
  
          "children": [  
  
            {  
  
              "elmType": "div",  
  
              "attributes": {  
  
                "class":"="  
  
              }  
  
            }  
  
          ]  
  
        }  
  
      ]  
  
    }  
  
  }  
  
}  

Thanks

Microsoft 365 and Office | SharePoint | For business | Windows
{count} votes

1 answer

Sort by: Most helpful
  1. Emily Du-MSFT 51,846 Reputation points Microsoft External Staff
    2021-08-09T09:24:59.937+00:00

    @harry777

    Per my test, through JSON formatting, setting the color of “Project" column header according to the value of “Status” column is not available.

    You could set the color of “Project" column header according to the text of “Project" column by using JSON formatting.

    {  
      "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json",  
      "groupProps": {  
        "hideFooter": false,  
        "headerFormatter": {  
          "elmType": "div",  
          "style": {  
            "background-color":"=if(@group.fieldData == 'Project1', 'green','red')",  
            "flex-wrap": "wrap",  
            "display": "flex",  
            "box-sizing": "border-box",  
            "padding": "4px 8px 5px 8px",  
            "border-radius": "6px",  
            "align-items": "center",  
            "white-space": "nowrap",  
            "overflow": "hidden",  
            "margin": "1px 4px 4px 1px"  
          },  
          "children": [  
            {  
              "elmType": "div",  
              "children": [  
                {  
                  "elmType": "div",  
                  "style": {  
                    "display": "flex",  
                    "flex-direction": "row",  
                    "justify-content": "center"  
                  },  
                  "children": [  
                    {  
                      "elmType": "div",  
                      "txtContent": "=  @group.count",  
                      "style": {  
                        "padding": "5px 5px 5px 5px",  
                        "font-weight": "500"  
                      }  
                    }  
                  ]  
                }  
              ]  
            },  
            {  
              "elmType": "div",  
              "children": [  
                {  
                  "elmType": "div",  
                  "style": {  
                    "display": "flex",  
                    "flex-direction": "row",  
                    "justify-content": "center"  
                  },  
                  "children": [  
                    {  
                      "elmType": "div",  
                      "txtContent": "=  @group.fieldData.displayValue +'(s)  ' ",  
                      "style": {  
                        "padding": " ",  
                        "font-weight": "500"  
                      }  
                    }  
                  ]  
                }  
              ]  
            }  
          ]  
        }  
      }  
    }  
    

    Result:

    121569-1.png


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.