如何动态更改剑道网格的列集 [英] How to change columns set of kendo grid dynamically
本文介绍了如何动态更改剑道网格的列集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var grid = $( #grid )的数据( kendoGrid);
$ http.get('/ api / GetGridColumns')
.success(函数(数据){
grid.columns = data;
})
.error (function(data){
console.log(data);
});
这会更改列集合,但不会立即反映在我的网格中。但是,当我尝试在网格中执行某些操作(如分组)时,则会出现我的新列集。
请让我知道我该如何实现这一点。 / p>
问候,
Dilip Kumar
解决方案
它通过设置KendoUI数据源,销毁网格并重建它。
$(#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);
}
});
});
这里您可以这样做:
var options = grid.options;
options.columns = state.columns;
您可以在会话中或数据库中检索列
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
解决方案
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
这篇关于如何动态更改剑道网格的列集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文