Show / Hide columns programmatically in kendo grid
by manoj
HTML
<link rel="stylesheet" href="http://cdn.kendostatic.com/2013.2.716/styles/kendo.common.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2013.2.716/styles/kendo.default.min.css">
<script src="http://cdn.kendostatic.com/2013.2.716/js/jquery.min.js"></script>
<script src="http://cdn.kendostatic.com/2013.2.716/js/kendo.all.min.js"></script>
<script src="http://demos.kendoui.com/content/shared/js/people.js"></script>
<button id="show_col1" class="k-button">Show First Name</button>
<button id="hide_col1" class="k-button">Hide First Name</button>
<div id="grid"></div>
CSS
#grid {
width : 490px;
}
JavaScript
var ds = {
data : createRandomData(20),
pageSize: 10,
schema : {
model: {
fields: {
Id : { type: 'number' },
FirstName: { type: 'string' },
LastName : { type: 'string' },
City : { type: 'string' }
}
}
}
};
var grid = $("#grid").kendoGrid({
dataSource: ds,
editable : false,
pageable : true,
columns :
[
{ field: "FirstName", width: 90, title: "First Name" },
{ field: "LastName", width: 200, title: "Last Name" },
{ field: "City", width: 200 }
]
}).data("kendoGrid");
$("#show_col1").on("click", function() {
grid.showColumn(0);
});
$("#hide_col1").on("click", function() {
grid.hideColumn("FirstName");
});