How to change columns set of kendo grid dynamically

前端 未结 11 587
孤城傲影
孤城傲影 2020-12-04 19:08

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\         


        
11条回答
  •  既然无缘
    2020-12-04 19:24

    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

提交回复
热议问题