how to check and change color of cell value in kendo ui grid

padh

i am using kendo ui grid in MVC4 project. Below is my code

        @(Html.Kendo().Grid(Model)
    .Name("gridexcel")
    .Columns(columns =>
    {
        columns.Bound(c => c.ExcelId).Title("Id").Visible(false);
        columns.Bound(c => c.status).Title("Status").Width(100);
        columns.Bound(c => c.report_date).Title("Report Date");
        columns.Bound(c => c.code).Width(50);

and columns from 1 to 50... }

Here i want to check cells of columns from 1 to 50, whether it contains 0 or 1. if 0 then i want to change background color. please help..

Rich Hildebrand

Here is a a jsbin of what you described

http://jsbin.com/zusutigi/17/edit?css,js,output

To accomplish this, first hook into the DataBound event in your kendo mvc wrapper. http://docs.telerik.com/kendo-ui/api/wrappers/aspnet-mvc/kendo.mvc.ui.fluent/grideventbuilder

...
.Name("gridexcel")
.Events(events => events.DataBound(
        @<text>
            onDataBound
            </text>
            ))
        )
...

Then to check all cells in columns 1 - 50 for a 1 or a 0 you would add this javascript.

var containsOne = function(checkForOne) {
   return checkForOne.indexOf("1") >= 0;
};

var containsZero = function(checkForZero) {
  return checkForZero.indexOf("0") >= 0;
};

var addClassForOnes = function(element) {
  var text = element.textContent; 
  if (containsOne(text)) {
    $(element).addClass('has-one');
  }
};

var addClassForZeros = function(element) {
  var text = element.textContent; 
  if (containsZero(text)) {
    $(element).addClass('has-zero');
  }
};

var onDataBound = function() {
  var $gridCells = $('[role="gridcell"]');
  $gridCells.each(function(index, element) {
    console.log(element);
    addClassForOnes(element);
    addClassForZeros(element);
  });
};

Finally color the cells with the following css

.has-one {
  background-color: green;
}

.has-zero {
  background-color: red;
 }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to change the background of a cell dynamically in a Kendo MVC UI Grid?

Kendo UI Grid Anuglar Cell Color

How to get the first row corresponding cell value if i change the other rows cell value in kendo child grid

UI Grid RowTemplate color based on cell value

How to display icon as a value on a Kendo Grid cell?

How can i highlight the Kendo grid cell by color change after update

How to change the color of Kendo Grid elements

Kendo UI, How to manually call validate() on kendo grid cell

How to catch save row event of inline editing kendo ui grid and save the changes based on each cell change

ag Grid change cell color on Cell Value Change

How to get the value of a checkbox in a Kendo UI Grid?

Kendo UI data grid: How to change column display value based on status flag integer value

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

Change the class of a kendo ui cell

c# wpf how to change color of a cell in a data grid if its value is out of range

How can i get Selected Kendo Grid cell Value

How to make kendo grid cell blank when field value is zero

How to change color of selected row in kendo grid in angular

Check datagrid cell for value, if value is X change color of row

How to change the default filter operator in kendo ui grid mvc

Change color of cell in Grid (Vaadin)

How to automatically change color of cell if value is changed

Kendo UI grid conditionally editable cell

Kendo UI grid filter cell that contains an array

For a Windows Forms Application using `DataGridView`, how can I check a value in my DataSource and change the color of a separate cell?

How to change kendo ui scheduler event color programmatically

Kendo grid change style cell data

kendo ui Editable color input field on grid

Ui-Grid - Change background color cells same value