Skip to content

Fix(material/paginator): Table data does not get updated when paginat… #26903

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

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 2 additions & 6 deletions src/material/paginator/paginator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,10 @@ export abstract class _MatPaginatorBase<
return this._pageIndex;
}
set pageIndex(value: NumberInput) {
const previousPageIndex = this._pageIndex;
this._pageIndex = Math.max(coerceNumberProperty(value), 0);
this._changeDetectorRef.markForCheck();
this._emitPageEvent(previousPageIndex);
}
private _pageIndex = 0;

Expand Down Expand Up @@ -242,9 +244,7 @@ export abstract class _MatPaginatorBase<
return;
}

const previousPageIndex = this.pageIndex;
this.pageIndex = this.pageIndex + 1;
this._emitPageEvent(previousPageIndex);
}

/** Move back to the previous page if it exists. */
Expand All @@ -253,9 +253,7 @@ export abstract class _MatPaginatorBase<
return;
}

const previousPageIndex = this.pageIndex;
this.pageIndex = this.pageIndex - 1;
this._emitPageEvent(previousPageIndex);
}

/** Move to the first page if not already there. */
Expand All @@ -277,9 +275,7 @@ export abstract class _MatPaginatorBase<
return;
}

const previousPageIndex = this.pageIndex;
this.pageIndex = this.getNumberOfPages() - 1;
this._emitPageEvent(previousPageIndex);
}

/** Whether there is a previous page. */
Expand Down
12 changes: 12 additions & 0 deletions src/material/table/table.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,18 @@ describe('MDC-based MatTable', () => {
['a_10', 'b_10', 'c_10'],
['Footer A', 'Footer B', 'Footer C'],
]);

component.paginator.pageIndex = 0;
fixture.detectChanges();
expectTableToMatchContent(tableElement, [
['Column A', 'Column B', 'Column C'],
['a_1', 'b_1', 'c_1'],
['a_2', 'b_2', 'c_2'],
['a_3', 'b_3', 'c_3'],
['a_4', 'b_4', 'c_4'],
['a_5', 'b_5', 'c_5'],
['Footer A', 'Footer B', 'Footer C'],
]);
}));

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