简体   繁体   中英

Remove Columnmenu.columns from kendo ui grid

i'm working with KENDO UI Grid today, i need in a grid that in the columnmenu there are active the item "sort ascending, sort descending, columns, filter", but i need also that "columns" item disappear in the other columns, so that ppl can only hide from the first column. For example, in this code

<div id="grid"></div>
<script>
$("#grid").kendoGrid({
    columnMenu:true,
    filterable: true,
    sortable: true,
    columns: [
        { field: "productName" },
        { field: "category" }
    ],
    dataSource: [
       { productName: "Tea", category: "Beverages" },
        { productName: "Coffee", category: "Beverages" },
        { productName: "Ham", category: "Food" },
        { productName: "Bread", category: "Food" }
    ]
});
</script>

the result would be that in every column i'll get a menù with 4 item:

  1. sort ascending
  2. sort descending
  3. columns
  4. filter

now i need that only for "productName" column there are all 4 voices, and for "category" column (and for every other possible column), menu voice contain only:

  1. sort ascending
  2. sort descending
  3. filter

is that possible?

ty for any advice

It is not possible to configure this directly but you can remove the 'columns' menu entry on the Grid's columnMenuInit event (see http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#events-columnMenuInit ):

columnMenuInit: function(e) {

  // Only remove if column is not 'productName'
  if (e.field != "productName") {
    // Remove the item from the menu via JQuery
    e.container.find(".k-columns-item").remove();
  }
}

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