I am trying to change the menu option for a column from false to true and others from true to false when a user selects an item from a dropdown. This isn't working. I'm using getOptions(), changing the menu setting in each column, and then setOptions(options) to set it.
Here is a dojo showing an example. In the example, firstName and lastName are initially hidden. I simulate a user choosing last name from some sort of selector (like a dropdown box). The code should then hide both name columns and unhide the lastName column. Instead it hides both name columns.
It seems to have something to do with setting any of the name columns to hidden on initialization. If I remove this from the column settings on initialization though it only works once and when I choose a different option from the dropdown (dropdown is simulated in the dojo so you can't try this but trust me) it breaks.
<html> <head> <meta charset="utf-8"> <title>Untitled</title> <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2022.1.412/styles/kendo.common.min.css"> <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2022.1.412/styles/kendo.rtl.min.css"> <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2022.1.412/styles/kendo.default.min.css"> <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2021.2.511/styles/kendo.mobile.all.min.css"> <script src="https://code.jquery.com/jquery-1.12.3.min.js"></script> <script src="https://kendo.cdn.telerik.com/2021.2.511/js/angular.min.js"></script> <script src="https://kendo.cdn.telerik.com/2021.2.511/js/jszip.min.js"></script> <script src="https://kendo.cdn.telerik.com/2021.2.511/js/kendo.all.min.js"></script></head> <body> <div id="myGrid"></div> <script> let tableRows = [ { ID: 1, FirstName: "John", LastName: "Smith", Age: 21 }, { ID: 2, FirstName: "Jenny", LastName: "Jones", Age: 18 }, { ID: 3, FirstName: "Greg", LastName: "Adams", Age: 23 } ]; let tableColumns = [ { title: "Employee ID", field: "ID", width: 100, locked: true, menu: false }, { title: "First Name", field: "FirstName", width: 150, hidden: true, attributes: { "class": "name" }, }, { title: "Last Name", field: "LastName", hidden: true, width: 150, attributes: { "class": "name", "data-position": "last name" }, }, { title: "Age", field: "Age", width: 100 } ]; var grid = $(`#myGrid`).kendoGrid({ dataSource: { data: tableRows, schema: { model: { id: "ID", fields: { ID: {type: "number"}} } } }, dataBound: function (e) { if (e.sender.dataSource.view().length == 0) { var colspan = e.sender.thead.find("th").length; //insert empty row with colspan equal to the table header th count var emptyRow = "<tr><td colspan='" + colspan + "'></td></tr>"; e.sender.tbody.html(emptyRow); e.sender.table.width(800); } }, columns: tableColumns, columnMenu: true, sortable: true, pageable: false }).data("kendoGrid"); let options = grid.getOptions(); let columns = grid.columns; let nameColumns = $(".name"); let lastNameColumn = $("[data-position='last name']"); let lockedColumnCount = 0; for (var i = 0; i < columns.length; i++) { if (columns[i].locked) { lockedColumnCount++; } } $.each(nameColumns, function (index, element) { let elementIndex = $(element).index() + lockedColumnCount; //kendoGrids[tableId].showColumn(elementIndex); options.columns[elementIndex].menu = false; options.columns[elementIndex].hidden = true; }); // Let's pretend Last Name was chosen from a select box part of name to show. $.each(lastNameColumn, function (index, element) { let elementIndex = $(element).index() + lockedColumnCount; options.columns[elementIndex].menu = true; options.columns[elementIndex].hidden = false; //kendoGrids[tableId].showColumn(elementIndex); }); console.log(options); grid.options = options; grid.setOptions(options); </script> </body> </html>