I am trying to change the columns collection of my Kendo grid in the below way.
var grid = $("#grid").data("kendoGrid");
$http.get('/api/GetGridColumns')
.success(function (data) {
grid.columns = data;
})
.error(function (data) {
console.log(data);
});
This is changing the column collection but not reflecting immediately in my grid. But when I try to perform some actions in the grid (like grouping), then my new column set is appearing.
Please let me know how can I achieve this.
Regards, Dilip Kumar
Solution. The Kendo UI Grid with multi-header columns creates them with a data-title attribute equal to the current title of the column. To identify the column that needs to be updated we can use the tilde selector which does a contains search through the thead of the grid. Create a custom function updateColumnTitle .
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").
{ field: "DOR", title: "Release Date", format: "{0:MM/dd/yyyy}", }, { field: "rating", title: "Rating" }, { command: ["edit", "destroy"], title: " ", width: "250px" }
You can do it by setting the KendoUI datasource, destroy the grid, and rebuild it
$("#load").click(function () {
var grid = $("#grid").data("kendoGrid");
var dataSource = grid.dataSource;
$.ajax({
url: "/Home/Load",
success: function (state) {
state = JSON.parse(state);
var options = grid.options;
options.columns = state.columns;
options.dataSource.page = state.page;
options.dataSource.pageSize = state.pageSize;
options.dataSource.sort = state.sort;
options.dataSource.filter = state.filter;
options.dataSource.group = state.group;
grid.destroy();
$("#grid")
.empty()
.kendoGrid(options);
}
});
});
here you can just do this :
var options = grid.options;
options.columns = state.columns;
where you can retrieve the columns in a session or in a db
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With