Change color of group caption based on group value

I need example code on how to 

Change colour of group caption based on group value. below I want the grouping hear "Proposal Status: Active background to be green. etc.





1 Reply

RR Rajapandi Ravi Syncfusion Team July 21, 2025 07:34 AM UTC

Hi Mariusz,


Greetings from Syncfusion support


Based on your query, we could see that you like to change the background color of Group caption based on the status value. You can achieve your requirement by using the group caption template feature of Grid. We can add the condition as we want to render the Group caption with respective background color based on the value. Please refer the below code example and sample for more information.


Index.cshtml

 

<script id="captiontemplate" type="text/x-template">

    ${if(items[0].Checked)}

    <span class="active">

        ${field} - ${key}: ${count} items

    </span>

    ${else}

    <span class="inactive">

        ${field} - ${key}: ${count} items

    </span>

    ${/if}

</script>

 

 

<style>

.inactive {

     background-color: gray;

     color: white;

              }

 

.active {

      background-color: greenyellow;

      color: white;

              }

</style>

 

 


In this below sample, based on the Checked column value we have set the background color.


Sample: Check the attachment.


Documentation: https://ej2.syncfusion.com/aspnetcore/documentation/grid/grouping/caption-template



Regards,

Rajapandi R


Attachment: 197206sample_62a5142d.zip

Loader.
Up arrow icon