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

Hi,

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-columns>
            <e-grid-column field="OldValue" headerText="OldValue"></e-grid-column>
            <e-grid-column field="NewValue" headerText="NewValue"></e-grid-column>
        </e-grid-columns>

Example :

Old ValueNew Value
100g200g
SugarSugar
WhiteBrown
$5$2
AvailableAvailable

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-columns> 
        <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-columns> 
</ejs-grid> 
 
<style> 
    .e-grid td.e-rowcell.differentValue { 
        color: red; 
    } 
</style> 
 
<script> 
    function rowDataBound(args){ 
        if (args.data.OldValue != args.data.NewValue) 
            args.row.lastChild.classList.add('differentValue') 
    } 
</script> 


Refer the below screen shot. 

 

Refer the help documentation. 


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

Regards, 
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.  
                          
Regards, 
Thavasianand S.                         


Loader.
Live Chat Icon For mobile
Up arrow icon