简体   繁体   中英

How to remove a column from columnMenu list in Kendo grid

I have a Kendo grid like below:

$("#grid-primaryUser").kendoGrid({
    dataSource: UserDataSource,
    columns: [
        {
            title: 'Is Approver',
            template: "<input type='checkbox'/>"
        },
        {
            title: 'First Name',
            field: 'FirstName'
        },
        {
            title: 'Last Name',
            field: 'LastName'
        }
    ],
    toolbar: [
        { name: "save", text: app.common.resources.JS_.saveAll() }
    ],
    dataBound: function (e) {
        var grid = $("#grid-primaryUser").data("kendoGrid");
        var isAPACRegionOffice = $('#IsAPACRegionOffice').val() == 'True' ? true : false;
        if (grid != null && !isAPACRegionOffice) {
            grid.hideColumn(0);
            $("#grid-primaryUser").find(".k-grid-toolbar").detach();
        }
    },
    height: 250,
    groupable: false,
    sortable: true,
    pageable: false,
    resizable: true,
    reorderable: true,
    columnMenu: {
        messages: {
            sortAscending: app.common.resources.JS_.kendoGridColumnMenuSortAscending(),
            sortDescending: app.common.resources.JS_.kendoGridColumnMenuSortDescending(),
            columns: app.common.resources.JS_.kendoGridColumnMenuColumns(),
            unlock: app.common.resources.JS_Services_PropertyEventSearchService.kendoGridColumnMenuUnlock(),
            lock: app.common.resources.JS_Services_PropertyEventSearchService.kendoGridColumnMenuLock()
        }
    },
    columnMenuInit: function (e) {
        var item = e.container.find(".k-item k-state-default k-first");
        //item.prev(".k-separator").remove();
        item.remove();
    }
});

Here I can hide the first column based on the condition being true or false in DataBound property, but in columnMenu list it is still showing,

I need to remove the first column from columnMenu list as well, if it is hidden in the grid (from databound function) and this needs to be done in runtime.

I tried to do it using ColumnMenuInit property, but that does not seem to work or I may be missing something.

Set menu:false in the respective column's configuration:

http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#configuration-columns.menu

This will allow you to hide and show the column only programmatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM