Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

Commit 919eadb

Browse files
dlabrecqdgutride
authored andcommitted
fix(pagination): update lastPageNumber when config.totalItems is changed
Fixes #219
1 parent e50d55c commit 919eadb

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/app/pagination/pagination.component.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export class PaginationComponent implements DoCheck, OnInit {
8080
} else {
8181
this.config = cloneDeep(this.defaultConfig);
8282
}
83+
this.lastPageNumber = this.getLastPageNumber();
8384
this.pageNumber = this.config.pageNumber;
8485
this.prevConfig = cloneDeep(this.config);
8586
}
@@ -157,7 +158,7 @@ export class PaginationComponent implements DoCheck, OnInit {
157158
* Start Index of Current Page
158159
*/
159160
getStartIndex(): number {
160-
return this.config.totalItems ? this.config.pageSize * (this.config.pageNumber - 1) + 1 : 0;
161+
return (this.config.totalItems !== undefined) ? this.config.pageSize * (this.config.pageNumber - 1) + 1 : 0;
161162
}
162163

163164
/**
@@ -167,7 +168,7 @@ export class PaginationComponent implements DoCheck, OnInit {
167168
let numFullPages = Math.floor(this.config.totalItems / this.config.pageSize);
168169
let numItemsOnLastPage = this.config.totalItems - (numFullPages * this.config.pageSize) || this.config.pageSize;
169170
let numItemsOnPage = this.isLastPage() ? numItemsOnLastPage : this.config.pageSize;
170-
return this.config.totalItems ? this.getStartIndex() + numItemsOnPage - 1 : 0;
171+
return (this.config.totalItems !== undefined) ? this.getStartIndex() + numItemsOnPage - 1 : 0;
171172
}
172173

173174
/**
@@ -235,7 +236,7 @@ export class PaginationComponent implements DoCheck, OnInit {
235236
* Check if current Page is Last Page
236237
*/
237238
private isLastPage(): boolean {
238-
return this.config.pageNumber === this.lastPageNumber;
239+
return (this.config.pageNumber === this.lastPageNumber);
239240
}
240241
}
241242

0 commit comments

Comments
 (0)