Skip to content

Commit

Permalink
fix(picker): ColumnPicker/GridMenu exclude hiden cols when forceFitCo…
Browse files Browse the repository at this point in the history
…ls (#494)

- there was an issue happening when changing the "Force Fit Columns" flag with hidden columns, it was not respecting the list of columns and hidden columns were coming back as visible even though they were prior to the call hidden. in other words, calling "Force Fit" shouldn't change any columns visibility.
  • Loading branch information
ghiscoding authored May 18, 2020
1 parent 62d2c14 commit a29eff1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
20 changes: 13 additions & 7 deletions controls/slick.columnpicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@

function updateColumn(e) {
if ($(e.target).data("option") == "autoresize") {
if (e.target.checked) {
_grid.setOptions({ forceFitColumns: true });
_grid.autosizeColumns();
} else {
_grid.setOptions({ forceFitColumns: false });
}
// when calling setOptions, it will resize with ALL Columns (even the hidden ones)
// we can avoid this problem by keeping a reference to the visibleColumns before setOptions and then setColumns after
var previousVisibleColumns = getVisibleColumns();
var isChecked = e.target.checked;
_grid.setOptions({ forceFitColumns: isChecked });
_grid.setColumns(previousVisibleColumns);
return;
}

Expand All @@ -215,19 +215,25 @@
}

_grid.setColumns(visibleColumns);
onColumnsChanged.notify({ columns: visibleColumns, grid: _grid });
onColumnsChanged.notify({ allColumns: columns, columns: visibleColumns, grid: _grid });
}
}

function getAllColumns() {
return columns;
}

/** visible columns, we can simply get them directly from the grid */
function getVisibleColumns() {
return _grid.getColumns();
}

init(_grid);

return {
"init": init,
"getAllColumns": getAllColumns,
"getVisibleColumns": getVisibleColumns,
"destroy": destroy,
"updateAllTitles": updateAllTitles,
"onColumnsChanged": onColumnsChanged
Expand Down
12 changes: 6 additions & 6 deletions controls/slick.gridmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,12 +487,12 @@

function updateColumn(e) {
if ($(e.target).data("option") == "autoresize") {
if (e.target.checked) {
_grid.setOptions({ forceFitColumns: true });
_grid.autosizeColumns();
} else {
_grid.setOptions({ forceFitColumns: false });
}
// when calling setOptions, it will resize with ALL Columns (even the hidden ones)
// we can avoid this problem by keeping a reference to the visibleColumns before setOptions and then setColumns after
var previousVisibleColumns = getVisibleColumns();
var isChecked = e.target.checked;
_grid.setOptions({ forceFitColumns: isChecked });
_grid.setColumns(previousVisibleColumns);
return;
}

Expand Down

0 comments on commit a29eff1

Please sign in to comment.