Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: All option with changing totalRecords (#17025) #17227

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions packages/primeng/src/paginator/paginator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ export class Paginator extends BaseComponent implements OnInit, AfterContentInit
this.updatePageLinks();
this.updatePaginatorState();
this.updateFirst();
this.updateRowsPerPageOptions();
}

if (simpleChange.first) {
Expand Down Expand Up @@ -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 });
}
Expand All @@ -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] {
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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));
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/primeng/src/table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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, <number>first + <number>this.rows);
}
Expand Down
Loading