We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Set the color based on field data


I have a grid as shown example below, how can i set the color for the text field data in a column based on difference between 2 columns.

            <e-grid-column field="OldValue" headerText="OldValue"></e-grid-column>
            <e-grid-column field="NewValue" headerText="NewValue"></e-grid-column>

Example :

Old ValueNew Value

As per example, I want the text in New Value column which are Different than Old Value column.
In this case I want 200g, Brown & $2 to be in red color. Other than that is default black color.

Thank you.

3 Replies

TS Thavasianand Sankaranarayanan Syncfusion Team March 6, 2019 05:20 AM UTC

Hi Mohd, 

Greetings from Syncfusion. 

We can achieve your requirement using the rowDataBound event of Grid. 

Refer the below code example. 

<ejs-grid id="Grid" dataSource="ViewBag.dataSource" allowPaging="true" rowDataBound="rowDataBound"> 
        <e-grid-column field="OldValue" headerText="OldValue" width="90"></e-grid-column> 
        <e-grid-column field="NewValue" headerText="NewValue" width="90"></e-grid-column> 
    .e-grid td.e-rowcell.differentValue { 
        color: red; 
    function rowDataBound(args){ 
        if (args.data.OldValue != args.data.NewValue) 

Refer the below screen shot. 


Refer the help documentation. 

Please let us know if you need further assistance on this.  

Thavasianand S. 

MM Mohd Mohaimin Zakaria March 6, 2019 06:49 AM UTC

Got it. Thanks!

TS Thavasianand Sankaranarayanan Syncfusion Team March 7, 2019 05:08 AM UTC

Hi Mohd, 
We are happy that the problem has been solved. 
Please get back to us if you need any further assistance.  
Thavasianand S.                         

Live Chat Icon For mobile
Up arrow icon