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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Set the color based on field data

Thread ID:

Created:

Updated:

Platform:

Replies:

143103 Mar 5,2019 08:40 AM UTC Mar 7,2019 05:08 AM UTC ASP.NET Core - EJ 2 3
loading
Tags: DataGrid
Mohd Mohaimin Zakaria
Asked On March 5, 2019 08:40 AM UTC

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.

Thavasianand Sankaranarayanan [Syncfusion]
Replied On 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. 


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

Got it. Thanks!

Thavasianand Sankaranarayanan [Syncfusion]
Replied On 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.                         


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;