Skip to content

Commit

Permalink
fix(datatable-body): only access cache after init
Browse files Browse the repository at this point in the history
  • Loading branch information
Killusions committed Oct 22, 2024
1 parent 3f4280e commit 4a69611
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions projects/ngx-datatable/src/lib/components/body/body.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ export class DataTableBodyComponent<TRow extends { treeStatus?: TreeStatus } = a
}

rowHeightsCache: RowHeightCache = new RowHeightCache();
private cacheInit = signal(false);
rowsToRender = computed(() => {
return this.updateRows();
});
Expand Down Expand Up @@ -424,11 +425,6 @@ export class DataTableBodyComponent<TRow extends { treeStatus?: TreeStatus } = a

if (changes.pageSize) {
shouldRecalcLayout = true;

// Emits the page event if page size has been changed
this._offsetEvent = -1;
this.updatePage('up');
this.updatePage('down');
}

if (changes.rows) {
Expand Down Expand Up @@ -460,6 +456,14 @@ export class DataTableBodyComponent<TRow extends { treeStatus?: TreeStatus } = a
if (shouldRecalcLayout) {
this.recalcLayout();
}

// Do this after recalcLayout.
if (changes.pageSize) {
// Emits the page event if page size has been changed
this._offsetEvent = -1;
this.updatePage('up');
this.updatePage('down');
}
}

/**
Expand Down Expand Up @@ -800,6 +804,10 @@ export class DataTableBodyComponent<TRow extends { treeStatus?: TreeStatus } = a
* @memberOf DataTableBodyComponent
*/
rowsStyles = computed(() => {
if (!this.cacheInit()) {
return [];
}

const rowsStyles: NgStyle['ngStyle'][] = [];
this.rowsToRender().forEach((rows, index) => {
const styles: NgStyle['ngStyle'] = {};
Expand Down Expand Up @@ -847,7 +855,13 @@ export class DataTableBodyComponent<TRow extends { treeStatus?: TreeStatus } = a
* @memberOf DataTableBodyComponent
*/
bottomSummaryRowsStyles = computed(() => {
if (!this.scrollbarV || !this.rows || !this.rows.length || !this.rowsToRender()) {
if (
!this.scrollbarV ||
!this.rows ||
!this.rows.length ||
!this.rowsToRender() ||
!this.cacheInit()
) {
return null;
}

Expand Down Expand Up @@ -932,6 +946,8 @@ export class DataTableBodyComponent<TRow extends { treeStatus?: TreeStatus } = a
rowIndexes: this.rowIndexes,
rowExpansions
});

this.cacheInit.set(true);
}
}

Expand Down

0 comments on commit 4a69611

Please sign in to comment.