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

Apply css style to a row based on a value of its data

I have an ejGrid bound to a json datasource.
I'm able to style the single cells with an external script that read data from the data-style attribute and append to the <td> cells

What I'm trying to achieve now is to apply a style to the whole row, but the main issue with my current approach is that I have a frozen column, therefore we have two different tables.

In particular, I'd like to apply a smaller height to the Event Categories rows.
Event Categories are the ones with bold font, and in the data-source, they have a property type=c, highlighted in bold below:

[{"EventID": "c1","type":"c", "EventName": "Weather" },
{"EventID": "1", "EventName":"Rain","jun": "Monsoon starts","sep": "Light Rains"},
{"EventID": "3", "EventName":"Flood","jul": "Not Damaging"},
{"EventID": "4", "EventName":"Winter/Summer","apr": "Peak hot /excessive hot ","dec": "Average cold wave (5-6 degrees)"},
{"EventID": "c17","type":"c", "EventName": "Human Health" },....]


Is there a way to manage row styles?

Here is the playground with data sample:


Many thanks.
Best,
Marco



1 Reply

FS Farveen Sulthana Thameeztheen Basha Syncfusion Team January 2, 2018 04:41 PM UTC

Hi Marco, 

Thanks for contacting Syncfusion Support. 

Query # :- What I'm trying to achieve now is to apply a style to the whole row, but the main issue with my current approach is that I have a frozen column, 
 
We have checked your query and if you want to apply the CSS property to the whole row, we suggested you to use “rowDataBound” event of the Grid.  In the rowDataBound event, we can access the row data in args.data and based on that we have applied the CSS styles to the whole row.  Likewise, you can apply the CSS properties to the particular row as per your requirement. 

Please refer to the code example:- 
$(document).ready(function () { 
                $("#grid").ejGrid({ 
                    dataSource: progAct.typicalYear.data, 
                     
                    rowDataBound: function (args) { 
                        if (args.data.EventName == "Winter/Summer") 
                              args.row.css("backgroundColor", "#F3C3C3"); /*custom css applied to the row */ 
 
                    },   
                 
                }); 


Modified Sample Link:- 

Please refer to the API reference Link:- 

Please get back to us if you need any further assistance. 

Regards, 

Farveen sulthana T 




Loader.
Up arrow icon