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.
Unfortunately, activation email could not send to your email. Please try again.

Change background colour of a row based on value of a field

Thread ID:





132334 Aug 26,2017 09:09 PM Aug 29,2017 12:08 AM ASP.NET Core 3
Tags: Grid
James Wilkinson
Asked On August 26, 2017 09:09 PM

is it possible to change the background colour of a row in the grid based on the value of one of the fields?

For example if a Boolean field called Enabled = true then use the default background of White and if is false then use a an alternate background of grey.


Venkatesh Ayothi Raman [Syncfusion]
Replied On August 28, 2017 01:41 AM

Hi James, 

Thanks for contacting Syncfusion support. 

We have achieved your requirement using rowDataBound event in Grid. In this event, we can get the every row data details in “args.data” parameter. So, we can change the row background color in using this event as well as based on that corresponding value. Please refer to the following code example and Help documentation for more information, 

Code example: 
<ej-grid id="FlatGrid" datasource="@ViewBag.data" allow-sorting="true" allow-paging="true" row-data-bound="rowDataBound" > 
    . . . 
            <e-column field="OrderID" is-primary-key="true" header-text="Order ID" text-align="Right"></e-column> 
            <e-column field="CustomerID" header-text="Customer ID" edit-type="String"></e-column> 
            <e-column field="EmployeeID" header-text="EmployeeID " edit-type="Dropdown"></e-column> 

[row data bound event] 
function rowDataBound(e) { 
        if (e.data.CustomerID == "VINET") 
            e.row.css("background-color", 'red');//change the row background color based on customerID value 

Help documentation
1)       https://help.syncfusion.com/aspnet/grid/how-to/change-background-color-of-a-row-using-rowdatabound-event 
2)      https://help.syncfusion.com/api/js/ejgrid#events:rowdatabound 

Venkatesh Ayothiraman. 

James Wilkinson
Replied On August 28, 2017 08:16 AM

Thank-you.  That works nicely.


Venkatesh Ayothi Raman [Syncfusion]
Replied On August 29, 2017 12:08 AM

Hi James, 

Thanks for the feedback. 

We are very happy to hear that your requirement is achieved. 

Venkatesh Ayothiraman. 


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.

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.