Skip to content

Commit 825f330

Browse files
spike-rabbitfh1ch
authored andcommitted
refactor: convert rowCount to computed signal
1 parent ee9ffba commit 825f330

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

projects/ngx-datatable/src/lib/components/datatable.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
[ghostLoadingIndicator]="ghostLoadingIndicator()"
4343
[externalPaging]="externalPaging()"
4444
[rowHeight]="rowHeight()"
45-
[rowCount]="rowCount"
45+
[rowCount]="rowCount()"
4646
[offset]="offset"
4747
[trackByProp]="trackByProp()"
4848
[columns]="_internalColumns()"
@@ -94,8 +94,8 @@
9494
</div>
9595
@if (footerHeight()) {
9696
<datatable-footer
97-
[rowCount]="_internalGroupedRows() !== undefined ? _internalRows().length : rowCount"
98-
[groupCount]="_internalGroupedRows() !== undefined ? rowCount : undefined"
97+
[rowCount]="_internalGroupedRows() !== undefined ? _internalRows().length : rowCount()"
98+
[groupCount]="_internalGroupedRows() !== undefined ? rowCount() : undefined"
9999
[pageSize]="pageSize"
100100
[offset]="offset"
101101
[footerHeight]="footerHeight()"

projects/ngx-datatable/src/lib/components/datatable.component.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export class DatatableComponent<TRow extends Row = any>
234234
this._offset = val;
235235
}
236236
get offset(): number {
237-
return Math.max(Math.min(this._offset, Math.ceil(this.rowCount / this.pageSize) - 1), 0);
237+
return Math.max(Math.min(this._offset, Math.ceil(this.rowCount() / this.pageSize) - 1), 0);
238238
}
239239

240240
/**
@@ -667,7 +667,7 @@ export class DatatableComponent<TRow extends Row = any>
667667
}
668668
return 0;
669669
});
670-
rowCount = 0;
670+
readonly rowCount = computed(() => this.calcRowCount());
671671
rowDiffer: IterableDiffer<TRow | undefined> = inject(IterableDiffers).find([]).create();
672672
/** This counter is increased, when the rowDiffer detects a change. This will cause an update of _internalRows. */
673673
private readonly _rowDiffCount = signal(0);
@@ -766,12 +766,6 @@ export class DatatableComponent<TRow extends Row = any>
766766
// Recalculate without tracking other signals
767767
untracked(() => this.recalculateDims());
768768
});
769-
// Recalculates the rowCount when internal rows change
770-
// TODO: This should be a computed signal.
771-
effect(() => {
772-
this._internalRows();
773-
this.rowCount = untracked(() => this.calcRowCount());
774-
});
775769
}
776770

777771
/**
@@ -961,7 +955,6 @@ export class DatatableComponent<TRow extends Row = any>
961955
*/
962956
recalculatePages(): void {
963957
this.pageSize = this.calcPageSize();
964-
this.rowCount = this.calcRowCount();
965958
}
966959

967960
/**

0 commit comments

Comments
 (0)