Skip to content

Commit ef11eee

Browse files
authored
Merge pull request #6954 from IgniteUI/lastPage-equalTo-totalPages-82x
Change current page to equal last page, after changing perPage
2 parents 7c70376 + 54cf03d commit ef11eee

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

projects/igniteui-angular/src/lib/paginator/paginator.component.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ describe('IgxPaginator with default settings', () => {
3131
expect(totalPages).toBe(5);
3232
});
3333

34+
it('should change current page to equal last page, after changing perPage', () => {
35+
const fix = TestBed.createComponent(DefaultPaginatorComponent);
36+
fix.detectChanges();
37+
const paginator = fix.componentInstance.paginator;
38+
39+
paginator.paginate(paginator.totalPages - 1);
40+
paginator.perPage = paginator.totalRecords / 2;
41+
42+
fix.detectChanges();
43+
const page = paginator.page;
44+
expect(page).toBe(1);
45+
});
46+
3447
it('should disable go to first page when paginator is on first page', () => {
3548
const fix = TestBed.createComponent(DefaultPaginatorComponent);
3649
fix.detectChanges();

projects/igniteui-angular/src/lib/paginator/paginator.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ export class IgxPaginatorComponent extends DisplayDensityBase {
7979
this.perPageChange.emit(this._perPage);
8080
this._selectOptions = this.sortUniqueOptions(this.defaultSelectValues, this._perPage);
8181
this.totalPages = Math.ceil(this.totalRecords / this._perPage);
82+
if (this._page >= this.totalPages) {
83+
this._page = this.totalPages - 1;
84+
}
8285
}
8386

8487
/**

0 commit comments

Comments
 (0)