From 1d09d5d0dfbc71d0b471afbbe3e1d3ffbae025b1 Mon Sep 17 00:00:00 2001 From: Fenil Gandhi Date: Fri, 27 Dec 2024 12:18:19 +0530 Subject: [PATCH] fix: All option with changing totalRecords (#17025) --- packages/primeng/src/paginator/paginator.ts | 13 ++++++------- packages/primeng/src/table/table.ts | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/primeng/src/paginator/paginator.ts b/packages/primeng/src/paginator/paginator.ts index 3ce4e2bf789..4cdf0455764 100755 --- a/packages/primeng/src/paginator/paginator.ts +++ b/packages/primeng/src/paginator/paginator.ts @@ -400,7 +400,6 @@ export class Paginator extends BaseComponent implements OnInit, AfterContentInit this.updatePageLinks(); this.updatePaginatorState(); this.updateFirst(); - this.updateRowsPerPageOptions(); } if (simpleChange.first) { @@ -430,7 +429,7 @@ export class Paginator extends BaseComponent implements OnInit, AfterContentInit for (let opt of this.rowsPerPageOptions) { if (typeof opt == 'object' && opt['showAll']) { - showAllItem = { label: opt['showAll'], value: this.totalRecords }; + showAllItem = { label: opt['showAll'], value: -1 }; } else { this.rowsPerPageItems.push({ label: String(this.getLocalization(opt)), value: opt }); } @@ -451,7 +450,7 @@ export class Paginator extends BaseComponent implements OnInit, AfterContentInit } getPageCount(): number { - return Math.ceil(this.totalRecords / this.rows); + return this.rows > 0 ? Math.ceil(this.totalRecords / this.rows) : 1; } calculatePageLinkBoundaries(): [number, number] { @@ -491,7 +490,7 @@ export class Paginator extends BaseComponent implements OnInit, AfterContentInit 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, @@ -513,7 +512,7 @@ export class Paginator extends BaseComponent implements OnInit, AfterContentInit } getPage(): number { - return Math.floor(this.first / this.rows); + return this.rows > 0 ? Math.floor(this.first / this.rows) : 0; } changePageToFirst(event: Event): void { @@ -578,8 +577,8 @@ export class Paginator extends BaseComponent implements OnInit, AfterContentInit .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)); } } diff --git a/packages/primeng/src/table/table.ts b/packages/primeng/src/table/table.ts index c252122d784..535e7a251ba 100644 --- a/packages/primeng/src/table/table.ts +++ b/packages/primeng/src/table/table.ts @@ -38,8 +38,8 @@ import { FormsModule } from '@angular/forms'; import { BlockableUI, FilterMatchMode, FilterMetadata, FilterOperator, FilterService, LazyLoadMeta, OverlayService, PrimeTemplate, ScrollerOptions, SelectItem, SharedModule, SortMeta, TableState, TranslationKeys } from 'primeng/api'; import { BaseComponent } from 'primeng/basecomponent'; import { Button, ButtonModule } from 'primeng/button'; -import { DatePickerModule } from 'primeng/datepicker'; import { CheckboxModule } from 'primeng/checkbox'; +import { DatePickerModule } from 'primeng/datepicker'; import { ConnectedOverlayScrollHandler, DomHandler } from 'primeng/dom'; import { ArrowDownIcon } from 'primeng/icons/arrowdown'; import { ArrowUpIcon } from 'primeng/icons/arrowup'; @@ -1503,7 +1503,7 @@ export class Table extends BaseComponent implements OnInit, AfterViewInit, After 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); }