How to conditionally format a Kendo UI grid cell (depending on values) razor

Is there a way to conditionally format a cell in a Kendo UI cell depending on the value in that cell. I would also like to add a class to the grid cell depending on the value. ( ASP.net , C# , Razor )

PS

Decision

And I realized that.

 <script> function onDataBound(e) { $('td').each(function() { if ($(this).text() == 'Condition') { $(this).addClass('customClass'); } }); } </script> 

The grid looks like this:

 @(Html.Kendo().Grid<CustomStylesOnDataBound.ViewModels.EmployeeViewModel>() .Name("mvcGrid") .Columns(columns => { columns.Bound(p => p.EmployeeId).Width(100); columns.Bound(p => p.FirstName).Width(75); columns.Bound(p => p.LastName).Width(75); columns.Bound(p => p.Address); }) .Events(e => e.DataBound("onDataBound")) .Filterable() .Pageable() .DataSource(dataSource => dataSource .Ajax() .PageSize(50) .Read(read => read.Action("Employees_Read", "Home")) ) ) 

I'm not sure if there is a better solution for this, but it does its job. Ty peter

+4
source share
2 answers

Your question is discussed in this article in the code library.

0
source

I suggest you use $(e.sender.element).find('td').each for a selector.

Adding $(e.sender.element) limit your search to only the grid, otherwise if you have several tables on yours, you will also find cells in other tables.

Also, if you use $(e.sender.element).find('tr').each , you can use $(this.cells[0]).text() to check the various columns in your grid, and your purpose the class will look like this: $(this.cells[1]).addClass('customClass');

0
source

Source: https://habr.com/ru/post/1494216/


All Articles