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

Grid row color on conditions

2 Answers 1714 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pamela
Top achievements
Rank 1
Pamela asked on 13 Mar 2018, 11:27 PM

Hello,

i try to set row color on  conditions  in the dataBound event. But only in my first row the Color will set.


                    var grid = $('#@Model.Id()_grid').data("kendoGrid");
                    var gridData = grid.dataSource.view();

                    for (var i = 0; i < gridData.length; i++) {
                        var currentUid = gridData[i].uid;
                        var currentRow = grid.table.find("tr[data-uid='" + currentUid + "']");

                        if (gridData[i].Condision != 0) {
                            $(currentRow).addClass("Color"); //in css
                        }

                    }

 

I can not find the issure.

Thanks

Pamela

                

2 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 15 Mar 2018, 03:02 PM
Hi Pamela,

If you would like to have conditional styling in the Grid cells you can specify ClientTemplate for the column. Please check out the article below that illustrates different options for using ClientTemplate:


The configuration below shows a column that will render a cell with class redColor when the CompanyName contains the string "on". Otherwise the greenColor CSS class will be applied.

columns.Bound(c => c.CompanyName).ClientTemplate("<span class=#:CompanyName.indexOf('on')>0?'redColor':'greenColor'#>#:CompanyName#</span>");

Give the approach a try and let me know how it works for you.

Regards,
Viktor Tachev
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Pamela
Top achievements
Rank 1
answered on 21 Mar 2018, 11:11 AM
Thanks it works!
Tags
Grid
Asked by
Pamela
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Pamela
Top achievements
Rank 1
Share this question
or