From b38a1e8cce82b39a56ff2313e1fb1219a59b5a0e Mon Sep 17 00:00:00 2001 From: Fenil Gandhi <61816373+fenilg@users.noreply.github.com> Date: Tue, 17 Dec 2024 19:30:17 +0530 Subject: [PATCH 1/4] #17025 all records in paginator with dynamic rows (total records) --- src/app/components/paginator/paginator.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/app/components/paginator/paginator.ts b/src/app/components/paginator/paginator.ts index 97a7550fccd..c96d4235ff8 100755 --- a/src/app/components/paginator/paginator.ts +++ b/src/app/components/paginator/paginator.ts @@ -378,7 +378,6 @@ export class Paginator implements OnInit, AfterContentInit, OnChanges { this.updatePageLinks(); this.updatePaginatorState(); this.updateFirst(); - this.updateRowsPerPageOptions(); } if (simpleChange.first) { @@ -406,7 +405,7 @@ export class Paginator implements OnInit, AfterContentInit, OnChanges { this.rowsPerPageItems = []; for (let opt of this.rowsPerPageOptions) { if (typeof opt == 'object' && opt['showAll']) { - this.rowsPerPageItems.unshift({ label: opt['showAll'], value: this.totalRecords }); + this.rowsPerPageItems.unshift({ label: opt['showAll'], value: -1 }); } else { this.rowsPerPageItems.push({ label: String(this.getLocalization(opt)), value: opt }); } @@ -423,7 +422,7 @@ export class Paginator implements OnInit, AfterContentInit, OnChanges { } getPageCount(): number { - return Math.ceil(this.totalRecords / this.rows); + return this.rows > 0 ? Math.ceil(this.totalRecords / this.rows) : 1; } calculatePageLinkBoundaries(): [number, number] { @@ -463,7 +462,7 @@ export class Paginator implements OnInit, AfterContentInit, OnChanges { var pc = this.getPageCount(); if (p >= 0 && p < pc) { - this._first = this.rows * p; + this._first = this.rows > 0 ? this.rows * p : 0; var state = { page: p, first: this.first, @@ -485,7 +484,7 @@ export class Paginator implements OnInit, AfterContentInit, OnChanges { } getPage(): number { - return Math.floor(this.first / this.rows); + return this.rows > 0 ? Math.floor(this.first / this.rows) : 0; } changePageToFirst(event: Event): void { @@ -550,8 +549,8 @@ export class Paginator implements OnInit, AfterContentInit, OnChanges { .replace('{currentPage}', String(this.currentPage())) .replace('{totalPages}', String(this.getPageCount())) .replace('{first}', String(this.totalRecords > 0 ? this._first + 1 : 0)) - .replace('{last}', String(Math.min(this._first + this.rows, this.totalRecords))) - .replace('{rows}', String(this.rows)) + .replace('{last}', String(Math.min(this._first + (this.rows > 0 ? this.rows : this.totalRecords), this.totalRecords))) + .replace('{rows}', String((this.rows > 0 ? this.rows : this.totalRecords))) .replace('{totalRecords}', String(this.totalRecords)); } } From 59d60ed4574c9b1f79d346bfcca09c693f9cd375 Mon Sep 17 00:00:00 2001 From: Fenil Gandhi <61816373+fenilg@users.noreply.github.com> Date: Tue, 17 Dec 2024 19:34:45 +0530 Subject: [PATCH 2/4] #17025 render all rows, if rows (pageSize) not >0 --- src/app/components/table/table.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/components/table/table.ts b/src/app/components/table/table.ts index 266c5063996..1393b2e178a 100644 --- a/src/app/components/table/table.ts +++ b/src/app/components/table/table.ts @@ -1463,7 +1463,7 @@ export class Table implements OnInit, AfterViewInit, AfterContentInit, Blockable dataToRender(data: any) { const _data = data || this.processedData; - if (_data && this.paginator) { + if (_data && this.paginator && this.rows > 0) { const first = this.lazy ? 0 : this.first; return _data.slice(first, first + this.rows); } From ccf0cd5ea5fa9272509547b0b622eb099a79dd03 Mon Sep 17 00:00:00 2001 From: Fenil Gandhi <61816373+fenilg@users.noreply.github.com> Date: Wed, 18 Dec 2024 11:35:04 +0530 Subject: [PATCH 3/4] Prettier fix for paginator.ts --- src/app/components/paginator/paginator.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/components/paginator/paginator.ts b/src/app/components/paginator/paginator.ts index c96d4235ff8..bcc1bc5b0bf 100755 --- a/src/app/components/paginator/paginator.ts +++ b/src/app/components/paginator/paginator.ts @@ -322,7 +322,7 @@ export class Paginator implements OnInit, AfterContentInit, OnChanges { constructor( private cd: ChangeDetectorRef, private config: PrimeNGConfig - ) {} + ) { } ngOnInit() { this.updatePaginatorState(); @@ -560,4 +560,4 @@ export class Paginator implements OnInit, AfterContentInit, OnChanges { exports: [Paginator, DropdownModule, InputNumberModule, FormsModule, SharedModule], declarations: [Paginator] }) -export class PaginatorModule {} +export class PaginatorModule { } From 168b76f771f87a9feed03d0ace8a4bc4311b0b75 Mon Sep 17 00:00:00 2001 From: Fenil Gandhi <61816373+fenilg@users.noreply.github.com> Date: Wed, 18 Dec 2024 11:45:22 +0530 Subject: [PATCH 4/4] Update paginator.ts --- src/app/components/paginator/paginator.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/components/paginator/paginator.ts b/src/app/components/paginator/paginator.ts index bcc1bc5b0bf..28999d65133 100755 --- a/src/app/components/paginator/paginator.ts +++ b/src/app/components/paginator/paginator.ts @@ -322,7 +322,7 @@ export class Paginator implements OnInit, AfterContentInit, OnChanges { constructor( private cd: ChangeDetectorRef, private config: PrimeNGConfig - ) { } + ) {} ngOnInit() { this.updatePaginatorState(); @@ -550,7 +550,7 @@ export class Paginator implements OnInit, AfterContentInit, OnChanges { .replace('{totalPages}', String(this.getPageCount())) .replace('{first}', String(this.totalRecords > 0 ? this._first + 1 : 0)) .replace('{last}', String(Math.min(this._first + (this.rows > 0 ? this.rows : this.totalRecords), this.totalRecords))) - .replace('{rows}', String((this.rows > 0 ? this.rows : this.totalRecords))) + .replace('{rows}', String(this.rows > 0 ? this.rows : this.totalRecords)) .replace('{totalRecords}', String(this.totalRecords)); } } @@ -560,4 +560,4 @@ export class Paginator implements OnInit, AfterContentInit, OnChanges { exports: [Paginator, DropdownModule, InputNumberModule, FormsModule, SharedModule], declarations: [Paginator] }) -export class PaginatorModule { } +export class PaginatorModule {}