Skip to content

Commit

Permalink
fix: columnpicker and column order for hidden columns
Browse files Browse the repository at this point in the history
  • Loading branch information
6pac committed May 21, 2023
1 parent e61547e commit 034108d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
5 changes: 2 additions & 3 deletions controls/slick.columnpicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@

let columnId, columnLabel, excludeCssClass;
for (var i = 0; i < columns.length; i++) {
if (columns[i].hidden) continue;

columnId = columns[i].id;
excludeCssClass = columns[i].excludeFromColumnPicker ? "hidden" : "";

Expand All @@ -141,7 +139,7 @@

columnCheckboxes.push(checkboxElm);

if (_grid.getColumnIndex(columnId) != null) {
if (_grid.getColumnIndex(columnId) != null && !columns[i].hidden) {
checkboxElm.checked = true;
}

Expand Down Expand Up @@ -275,6 +273,7 @@
const columnId = e.target.dataset.columnid || '';
let visibleColumns = [];
columnCheckboxes.forEach((columnCheckbox, idx) => {
if (columns[idx].hidden !== undefined) { columns[idx].hidden = !columnCheckbox.checked; }
if (columnCheckbox.checked) {
visibleColumns.push(columns[idx]);
}
Expand Down
3 changes: 2 additions & 1 deletion examples/example-column-hidden.html
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ <h2>View Source:</h2>

document.querySelector('#chkHideColumn').addEventListener("change", function(e) {
var hideCol = document.querySelector('#chkHideColumn').checked || false;
columns[2].hidden = hideCol;
// use the grid's columns not the local column var, since order and visibility may have changed if we are still using the old technique to hide columns
grid.getColumns()[grid.getColumnIndex('duration')].hidden = hideCol;
grid.updateColumns();
});

Expand Down

0 comments on commit 034108d

Please sign in to comment.