hide and show columns- kendo grid

2019-09-06 14:43发布

How to hide and show columns of kendo grid without using jquery? here is the js fiddle link for the example: http://jsfiddle.net/tmLmk/7/

HTML code:

<div ng-controller="GridController">    
    <div kendo-grid k-options="options" k-data-source="sData"></div>
</div>

JS code:

angular.module('angular-kendo-example', ['kendo.directives']);

function GridController($scope) {
    $scope.options = {
        sortable: true,
        pageable: true,
        columns: [{
            field: "column1",
            title: "column 1",
            width: "40px"
        },{
            field: "column2",
            title: "column 2",
            width: "70px"
        },{
            field: "column3",
            title: "column 3",
            width: "70px"
        },{
            field: "column4",
            title: "column 4",
            width: "60px"
        },{
            field: "column5",
            title: "column 5",
            width: "40px"
        },{
            field: "column6",
            title: "column 6",
            width: "40px"
        }],

    };
    $scope.sData= [
        { column1: "column1 data", column2: "column2 data", column3: "column3 data", column4:  "column4 data",  column5: "column5 data", column6: "column6 data"  }, { column1: "column1 data", column2: "column2 data", column3: "column3 data", column4:  "column4 data",  column5: "column5 data", column6: "column6 data"  }, { column1: "column1 data", column2: "column2 data", column3: "column3 data", column4:  "column4 data",  column5: "column5 data", column6: "column6 data"  }
    ];
}

Thanks.

2条回答
爷的心禁止访问
2楼-- · 2019-09-06 15:22

Given the name of your Kendo UI Grid in AngularJS, in your case $scope.options

you can hide each column programmatically passing the column index, like that:

$scope.options.columns[3].hidden = true;
查看更多
混吃等死
3楼-- · 2019-09-06 15:33

If you add

columnMenu = true,

Before the columns declaration this should give you the column menu which should enable the show and hide columns options.

This link should help

http://demos.telerik.com/kendo-ui/grid/column-menu

查看更多
登录 后发表回答