$(function () {
//reference gridvar grid = $("#grid").data("kendoGrid");
//reference columnsvar columnValues = grid.columns;
//Create arrayvar checkedValues = [];
//for each column, add checked if hidden is undefined
$(columnValues).each(function (index) {
if (this.hidden == true) {
checkedValues.push(" ");
} else {
checkedValues.push("checked");
}
});
//reference the Kendo UI Menuvar menu = $("#columnMenu").data("kendoMenu");
//create initial first item
menu.append({ text: "Columns" });
//reference it through jQueryvar firstItem = $("#columnMenu").children("li").eq(0);
//for each column, append checkboxes with checked values based on hidden field
$(columnValues).each(function (index) {
menu.append({ text: "<input type='checkbox' " + checkedValues[index] + " />" + grid.columns[index].field, encoded: false }, firstItem);
});
});
functiononColumnMenuInit(e) {
var item = e.container.find(".k-columns-item");
item.prev(".k-separator").remove();
item.remove();
}
functiononSelect(e) {
//reference checkboxvar checkbox = $(e.item).find("input");
//reference the Gridvar grid = $("#grid").data("kendoGrid");
//hold the number of columnsvar numOfColumns = grid.columns.length;
//loop through to find how many columns are hiddenfor (var i = 0; i < grid.columns.length; i++) {
if (grid.columns[i].hidden == true) {
numOfColumns--;
}
}
//if the field matches the selected item, check if it is hidden or not.for (var i = 0; i < grid.columns.length; i++) {
if (grid.columns[i].field == e.item.innerText) {
//Show the hidden columnif (grid.columns[i].hidden == true) {
grid.showColumn(grid.columns[i].field);
//check box
$(checkbox).prop("checked", true);
//it will hide as long as there is more than one column in the Grid
} elseif (numOfColumns != 1) {
grid.hideColumn(grid.columns[i].field);
//uncheck box
$(checkbox).prop("checked", false);
} else {
//check box if it's the last item
$(checkbox).prop("checked", true);
}
}
}
}
Additionally, I have found a feature request asking for the functionality to be added in the future which is currently under review. I have added a vote on your behalf, feel free to add any comments for the development community, and I recommend following it for any potential updates.