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: Data table pagination issue for dynamic rows for showAll option (Issue: 17025) #17095

Open
wants to merge 4 commits into
base: v17-prod
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 src/app/components/paginator/paginator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@ export class Paginator implements OnInit, AfterContentInit, OnChanges {
this.updatePageLinks();
this.updatePaginatorState();
this.updateFirst();
this.updateRowsPerPageOptions();
}

if (simpleChange.first) {
Expand Down Expand Up @@ -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 });
}
Expand All @@ -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] {
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, <number>first + <number>this.rows);
}
Expand Down
Loading