hide and show columns- kendo grid

大兔子大兔子 提交于 2019-12-12 04:56:57

问题


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.


回答1:


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




回答2:


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;


来源:https://stackoverflow.com/questions/24238403/hide-and-show-columns-kendo-grid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!