Skip to content

Commit 89ac11b

Browse files
committed
fix(material/paginator): emit events when page index is updated
1 parent 357cfd3 commit 89ac11b

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

src/material/paginator/paginator.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ export class MatPaginator implements OnInit, OnDestroy {
137137
return this._pageIndex;
138138
}
139139
set pageIndex(value: number) {
140-
this._pageIndex = Math.max(value || 0, 0);
141-
this._changeDetectorRef.markForCheck();
140+
this._navigate(value);
142141
}
143142
private _pageIndex = 0;
144143

@@ -306,11 +305,8 @@ export class MatPaginator implements OnInit, OnDestroy {
306305
// Current page needs to be updated to reflect the new page size. Navigate to the page
307306
// containing the previous page's first item.
308307
const startIndex = this.pageIndex * this.pageSize;
309-
const previousPageIndex = this.pageIndex;
310-
311-
this.pageIndex = Math.floor(startIndex / pageSize) || 0;
312308
this.pageSize = pageSize;
313-
this._emitPageEvent(previousPageIndex);
309+
this.pageIndex = Math.floor(startIndex / pageSize) || 0;
314310
}
315311

316312
/** Checks whether the buttons for going forwards should be disabled. */
@@ -361,11 +357,11 @@ export class MatPaginator implements OnInit, OnDestroy {
361357

362358
/** Navigates to a specific page index. */
363359
private _navigate(index: number) {
364-
const previousIndex = this.pageIndex;
365-
366-
if (index !== previousIndex) {
367-
this.pageIndex = index;
368-
this._emitPageEvent(previousIndex);
360+
if (index !== this.pageIndex) {
361+
const previousPageIndex = this._pageIndex;
362+
this._pageIndex = Math.max(index || 0, 0);
363+
this._changeDetectorRef.markForCheck();
364+
this._emitPageEvent(previousPageIndex);
369365
}
370366
}
371367

src/material/table/table.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,18 @@ describe('MatTable', () => {
566566
['a_10', 'b_10', 'c_10'],
567567
['Footer A', 'Footer B', 'Footer C'],
568568
]);
569+
570+
component.paginator.pageIndex = 0;
571+
fixture.detectChanges();
572+
expectTableToMatchContent(tableElement, [
573+
['Column A', 'Column B', 'Column C'],
574+
['a_1', 'b_1', 'c_1'],
575+
['a_2', 'b_2', 'c_2'],
576+
['a_3', 'b_3', 'c_3'],
577+
['a_4', 'b_4', 'c_4'],
578+
['a_5', 'b_5', 'c_5'],
579+
['Footer A', 'Footer B', 'Footer C'],
580+
]);
569581
}));
570582

571583
it('should sort strings with numbers larger than MAX_SAFE_INTEGER correctly', () => {

0 commit comments

Comments
 (0)