Skip to content

Commit f780ebb

Browse files
spike-rabbitfh1ch
authored andcommitted
refactor: convert pageSize to computed signal
1 parent ee9ffba commit f780ebb

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
[offset]="offset"
4747
[trackByProp]="trackByProp()"
4848
[columns]="_internalColumns()"
49-
[pageSize]="pageSize"
49+
[pageSize]="pageSize()"
5050
[offsetX]="_offsetX"
5151
[rowDetail]="rowDetail"
5252
[groupHeader]="groupHeader"
@@ -96,7 +96,7 @@
9696
<datatable-footer
9797
[rowCount]="_internalGroupedRows() !== undefined ? _internalRows().length : rowCount"
9898
[groupCount]="_internalGroupedRows() !== undefined ? rowCount : undefined"
99-
[pageSize]="pageSize"
99+
[pageSize]="pageSize()"
100100
[offset]="offset"
101101
[footerHeight]="footerHeight()"
102102
[footerTemplate]="footer"

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

Lines changed: 6 additions & 7 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
/**
@@ -656,7 +656,7 @@ export class DatatableComponent<TRow extends Row = any>
656656

657657
element = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
658658
readonly _innerWidth = computed(() => this.dimensions().width);
659-
pageSize!: number;
659+
readonly pageSize = computed(() => this.calcPageSize());
660660
readonly bodyHeight = computed(() => {
661661
if (this.scrollbarV()) {
662662
let height = this.dimensions().height;
@@ -823,7 +823,7 @@ export class DatatableComponent<TRow extends Row = any>
823823
if (this.externalPaging() && this.scrollbarV()) {
824824
this.page.emit({
825825
count: this.count(),
826-
pageSize: this.pageSize,
826+
pageSize: this.pageSize(),
827827
limit: this.limit(),
828828
offset: 0,
829829
sorts: this.sorts()
@@ -960,7 +960,6 @@ export class DatatableComponent<TRow extends Row = any>
960960
* Recalculates the pages after a update.
961961
*/
962962
recalculatePages(): void {
963-
this.pageSize = this.calcPageSize();
964963
this.rowCount = this.calcRowCount();
965964
}
966965

@@ -980,7 +979,7 @@ export class DatatableComponent<TRow extends Row = any>
980979
if (!isNaN(this.offset)) {
981980
this.page.emit({
982981
count: this.count(),
983-
pageSize: this.pageSize,
982+
pageSize: this.pageSize(),
984983
limit: this.limit(),
985984
offset: this.offset,
986985
sorts: this.sorts()
@@ -1005,7 +1004,7 @@ export class DatatableComponent<TRow extends Row = any>
10051004

10061005
this.page.emit({
10071006
count: this.count(),
1008-
pageSize: this.pageSize,
1007+
pageSize: this.pageSize(),
10091008
limit: this.limit(),
10101009
offset: this.offset,
10111010
sorts: this.sorts()
@@ -1160,7 +1159,7 @@ export class DatatableComponent<TRow extends Row = any>
11601159
// Emit the page object with updated offset value
11611160
this.page.emit({
11621161
count: this.count(),
1163-
pageSize: this.pageSize,
1162+
pageSize: this.pageSize(),
11641163
limit: this.limit(),
11651164
offset: this.offset,
11661165
sorts: this.sorts()

0 commit comments

Comments
 (0)