kul_mi
kul_mi

Reputation: 1151

Kendo UI grid hide columns with zero values

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?

Upvotes: 5

Views: 6135

Answers (1)

Atanas Korchev
Atanas Korchev

Reputation: 30661

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");
}

Upvotes: 8

Related Questions