Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kendo UI grid hide columns with zero values

Tags:

c#

kendo-ui

I would like to hide those columns (that contain integer values) in my Kendo Grid in which all cells contain '0' values. Is the solution for that easy?

like image 557
kul_mi Avatar asked Nov 28 '12 11:11

kul_mi


People also ask

How do I hide Kendo grid column dynamically?

You showing/hiding columns in KendoUI Grid you should use showColumn and hideColumn and use as argument a number (the index of the column that you want to show/hide) or a string (the name of the field associated in that column). Example: var grid = $("#grid").


1 Answers

You can hide a column via the hideColumn method. You can get the data to which the grid is bound to using the data method of the data source. Then traverse it to find if all records contain zeros. Here is a quick example:

var grid = $("#grid").data("kendoGrid");
var data = grid.dataSource.data();

var allZeroes = true;

for (var i = 0; i < data.length; i++) {
    // say the name of the field to which the column is bound is "foo"
    if (data[i].foo != 0) { 
       allZeroes = false;

       break;
    }
}

if (allZeroes) {
   grid.hideColumn("foo");
}
like image 199
Atanas Korchev Avatar answered Oct 14 '22 10:10

Atanas Korchev