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: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to customize foreground color of rows /cells in Grid?

Thread ID:

Created:

Updated:

Platform:

Replies:

146847 Aug 22,2019 01:35 PM UTC Aug 23,2019 06:30 AM UTC Blazor 1
loading
Tags: Grid
Mr Andrey Voronov
Asked On August 22, 2019 01:35 PM UTC

Code provided in documentation works for background color only, adding styles color:green has no impact on grid appearance

<style>
    .below-25 {
        background-color: orangered;
    }

    .below-35 {
        background-color: yellow;
    }

    .above-35 {
        background-color: greenyellow
    }
</style>

Vignesh Natarajan [Syncfusion]
Replied On August 23, 2019 06:30 AM UTC

Hi Mr Andrey,  

Greetings from Syncfusion support.  

Query: “Code provided in documentation works for background color only, adding styles color:green has no impact on grid appearance 

We are able to reproduce the reported behavior (styles are not applied when using color attribute) at our end also. Because we will not set any background color attribute for td element (.e-rowcell). So while defining the style (background-color) in the sample level it get reflected in DOM element.  

But we will set color as black by default for td element(e-rowcell class) hence the color property value is not override in the same way that you have defined for background color CSS. Kindly refer the below method to override the color attribute for td element. 

<EjsGrid DataSource="@Orders" AllowPaging="true"> 
    <GridEvents QueryCellInfo="QueryCellInfoHandler" TValue="Order"></GridEvents> 
    ………………………. 
</EjsGrid> 
<style> 
    .e-grid .e-gridcontent .e-rowcell.below-35 { 
        color: orangered; 
    } 
……………………… 
</style> 
@code{ 
…….. 
    public void QueryCellInfoHandler(QueryCellInfoEventArgs<Order> args) 
    { 
        if(args.Data.Freight > 35) 
        { 
            args.Cell.AddClass(new string[] { "below-35" }); 
        } 
………………………. 
    } 
} 


Note: You can also use SetAttribute method in QueryCellInfo event to apply style directly to Grid. But SetAttribute will override the default style applied to Grid cell (i.e) textalign. Refer the below code example,  

public void QueryCellInfoHandler(QueryCellInfoEventArgs<Order> args) 
    { 
        if(args.Data.Freight > 35) 
        { 
            args.Cell.SetAttribute("style", "color:green"); 
        } 
        else if(args.Data.Freight > 25) 
        { 
            args.Cell.SetAttribute("style", "color:yellow"); 
        } 
……………………………… 
    } 

Please get back to us if you have any other queries.   
  
Regards, 
Vignesh Natarajan. 


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

Live Chat Icon For mobile
Live Chat Icon