I am done with this. Dion's solution gave me the idea of ββusing colg groups, but this solution is limited by the absence of locked columns, which is in different groups.
Also note: I do not want to use grid.setOptions, because of its limitations, destroying the attached events and the header (in the case of using the ASP MVC helper to render the grid)
function setColumnWidths(grid, options) { var lockedCount = 0; for (var i = 0; i < options.columns.length; i++) { if (options.columns[i].hasOwnProperty('locked')) { if (options.columns[i].locked) { lockedCount++; } } } for (var i = 0; i < options.columns.length; i++) { var width = options.columns[i].width; grid.columns[i].width = width; if (options.columns[i].hasOwnProperty('locked') && options.columns[i].locked) { $("#grid .k-grid-header-locked").find("colgroup col").eq(i).width(width); $("#grid .k-grid-content-locked").find("colgroup col").eq(i).width(width); } else { $("#grid .k-grid-header-wrap").find("colgroup col").eq(i-lockedCount).width(width); $("#grid .k-grid-content").find("colgroup col").eq(i - lockedCount).width(width); } } // Hack to refresh grid visual state grid.reorderColumn(1, grid.columns[0]); grid.reorderColumn(1, grid.columns[0]); }
source share