Skip to content

Commit

Permalink
fix(frozen): in some occasion column pinning changes column positions
Browse files Browse the repository at this point in the history
- in some rare occasion changing the pinning (frozen column) will change the column positions shown in the grid and that is because of a bug that is in the SlickGrid core lib, we can however circumvent it by keeping a copy of the columns and re-applying them right after changing the pinning
  • Loading branch information
ghiscoding committed Jun 1, 2021
1 parent 51de889 commit 70cb74e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion packages/common/src/extensions/headerMenuExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,12 @@ export class HeaderMenuExtension implements Extension {
const visibleColumns = [...this.sharedService.visibleColumns];
const columnPosition = visibleColumns.findIndex(col => col.id === args.column.id);
const newGridOptions = { frozenColumn: columnPosition, enableMouseWheelScrollHandler: true };
this.sharedService.slickGrid.setOptions(newGridOptions);

// to circumvent a bug in SlickGrid core lib, let's keep the columns positions ref and re-apply them after calling setOptions
// the bug is highlighted in this issue comment:: https://github.com/6pac/SlickGrid/issues/592#issuecomment-822885069
const previousColumnDefinitions = this.sharedService.slickGrid.getColumns();

this.sharedService.slickGrid.setOptions(newGridOptions, false, true); // suppress the setColumns (3rd argument) since we'll do that ourselves
this.sharedService.gridOptions.frozenColumn = newGridOptions.frozenColumn;
this.sharedService.gridOptions.enableMouseWheelScrollHandler = newGridOptions.enableMouseWheelScrollHandler;
this.sharedService.frozenVisibleColumnId = args.column.id;
Expand All @@ -380,6 +385,9 @@ export class HeaderMenuExtension implements Extension {
// to make sure that we only use the visible columns, not doing this will have the undesired effect of showing back some of the hidden columns
if (this.sharedService.hasColumnsReordered || (Array.isArray(visibleColumns) && Array.isArray(this.sharedService.allColumns) && visibleColumns.length !== this.sharedService.allColumns.length)) {
this.sharedService.slickGrid.setColumns(visibleColumns);
} else {
// to circumvent a bug in SlickGrid core lib re-apply same column definitions that were backend up before calling setOptions()
this.sharedService.slickGrid.setColumns(previousColumnDefinitions);
}

// we also need to autosize columns if the option is enabled
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/interfaces/slickGrid.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ export interface SlickGrid {
* Apply Columns Widths in the UI and optionally invalidate & re-render the columns when specified
* @param {Boolean} shouldReRender - should we invalidate and re-render the grid?
*/
reRenderColumns(shouldReRender: boolean): void;
reRenderColumns(shouldReRender?: boolean): void;

/** Resets active cell. */
resetActiveCell(): void;
Expand Down
Binary file not shown.

0 comments on commit 70cb74e

Please sign in to comment.