Skip to content

Commit

Permalink
perf(resizer): autosizeColumns is called too many times on page load (
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Jan 19, 2024
1 parent 8b418f2 commit f4f64b3
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions packages/aurelia-slickgrid/src/custom-elements/aurelia-slickgrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export class AureliaSlickgridCustomElement {
protected _eventHandler!: SlickEventHandler;
protected _eventPubSubService!: EventPubSubService;
protected _hideHeaderRowAfterPageLoad = false;
protected _isAutosizeColsCalled = false;
protected _isGridInitialized = false;
protected _isDatasetInitialized = false;
protected _isDatasetHierarchicalInitialized = false;
Expand Down Expand Up @@ -291,6 +292,7 @@ export class AureliaSlickgridCustomElement {

this.gridOptions.translater = this.translaterService;
this._eventHandler = eventHandler;
this._isAutosizeColsCalled = false;

// when detecting a frozen grid, we'll automatically enable the mousewheel scroll handler so that we can scroll from both left/right frozen containers
if (this.gridOptions && ((this.gridOptions.frozenRow !== undefined && this.gridOptions.frozenRow >= 0) || this.gridOptions.frozenColumn !== undefined && this.gridOptions.frozenColumn >= 0) && this.gridOptions.enableMouseWheelScrollHandler === undefined) {
Expand Down Expand Up @@ -640,8 +642,9 @@ export class AureliaSlickgridCustomElement {

// expand/autofit columns on first page load
// we can assume that if the oldValue was empty then we are on first load
if (this.gridOptions.autoFitColumnsOnFirstLoad && (!oldValue || oldValue.length < 1)) {
if (this.grid && this.gridOptions.autoFitColumnsOnFirstLoad && (!oldValue || oldValue.length < 1) && !this._isAutosizeColsCalled) {
this.grid.autosizeColumns();
this._isAutosizeColsCalled = true;
}
}

Expand Down Expand Up @@ -880,22 +883,17 @@ export class AureliaSlickgridCustomElement {
throw new Error(`[Aurelia-Slickgrid] You cannot enable both autosize/fit viewport & resize by content, you must choose which resize technique to use. You can enable these 2 options ("autoFitColumnsOnFirstLoad" and "enableAutoSizeColumns") OR these other 2 options ("autosizeColumnsByCellContentOnFirstLoad" and "enableAutoResizeColumnsByCellContent").`);
}

// expand/autofit columns on first page load
if (grid && options.autoFitColumnsOnFirstLoad && options.enableAutoSizeColumns && typeof grid.autosizeColumns === 'function') {
this.grid.autosizeColumns();
}

// auto-resize grid on browser resize
if (options.gridHeight || options.gridWidth) {
this.resizerService.resizeGrid(0, { height: options.gridHeight, width: options.gridWidth });
} else {
this.resizerService.resizeGrid();
}

if (grid && options?.enableAutoResize) {
if (options.autoFitColumnsOnFirstLoad && options.enableAutoSizeColumns && typeof grid.autosizeColumns === 'function') {
grid.autosizeColumns();
}
// expand/autofit columns on first page load
if (grid && options?.enableAutoResize && options.autoFitColumnsOnFirstLoad && options.enableAutoSizeColumns && !this._isAutosizeColsCalled) {
grid.autosizeColumns();
this._isAutosizeColsCalled = true;
}
}

Expand Down Expand Up @@ -1021,6 +1019,14 @@ export class AureliaSlickgridCustomElement {
return showing;
}

setData(data: any[], shouldAutosizeColumns = false) {
if (shouldAutosizeColumns) {
this._isAutosizeColsCalled = false;
this._currentDatasetLength = 0;
}
this.dataset = data || [];
}

/**
* Check if there's any Pagination Presets defined in the Grid Options,
* if there are then load them in the paginationOptions object
Expand Down

0 comments on commit f4f64b3

Please sign in to comment.