Skip to content

Commit 9958875

Browse files
authored
Merge pull request #6955 from IgniteUI/lastPage-equalTo-totalPages-90x
Change current page to equal last page, after changing perPage
2 parents 302617c + 480c4b3 commit 9958875

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
@@ -32,6 +32,19 @@ describe('IgxPaginator with default settings', () => {
3232
expect(totalPages).toBe(5);
3333
});
3434

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