This is a migrated thread and some comments may be shown as answers.

Is there a way to conditionally style a row for grid wrapper?

1 Answer 72 Views
Grid
This is a migrated thread and some comments may be shown as answers.
n/a
Top achievements
Rank 1
n/a asked on 31 Jul 2019, 01:29 PM

 I am wanting to style a row and just change the background color based on the value of a certain cell of the row. 

 

I am unsure on how to do this. 

1 Answer, 1 is accepted

Sort by
0
Petar
Telerik team
answered on 02 Aug 2019, 01:04 PM
Hi Yovanys,

I've used this Row template example from our documentation as a basis and modified it in a way to demonstrate how the desired functionality could be achieved. 

Here is the modified project: https://stackblitz.com/edit/eyxaed?file=index.js

The demonstrated approach uses the approach we use when working with regular Kendo Templates. In the above example, the difference versus the original example is the definition of the generateAltRowTemplate method in the index.js file. Here is it:

generateAltRowTemplate: function() {
            var template =
 '#if(Country !== "USA"){ console.log(Country);#'+
                '<tr class="k-alt" data-uid="#: uid #">' +
                    '<td class="details">' +
                        '<span class="name">#: FirstName# #: LastName# </span>' +
                        '<span class="title">Title: #: Title #</span>' +
                    '</td>' +
                    '<td class="country">' +
                        '#: Country #' +
                    '</td>' +
                    '<td class="employeeID">' +
                        '#: EmployeeID #' +
                    '</td>' +
                '</tr>'+
                '#}else{console.log(Country);#' +
                 '<tr style="background-color:red" data-uid="#: uid #">' +
                    '<td class="details">' +
                        '<span class="name">#: FirstName# #: LastName# </span>' +
                        '<span class="title">Title: #: Title #</span>' +
                    '</td>' +
                    '<td class="country">' +
                        '#: Country #' +
                    '</td>' +
                    '<td class="employeeID">' +
                        '#: EmployeeID #' +
                    '</td>'
                + '#}#'

What we do with the above snippet is to check the value of the Country field in each even row of the Grid. If the value is equal to "USA" then we set a red background color to the current row. 

I hope the given implementation will help you resolve your issue. If you have questions, please let me know. 

Regards,
Petar
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
n/a
Top achievements
Rank 1
Answers by
Petar
Telerik team
Share this question
or