MatPaginator does not work with dynamic data
See original GitHub issueBug, feature request, or proposal:
MatPaginator does not work properly with dynamically loaded data
What is the expected behavior?
MatPaginator should work the same even if the table/paginator are within *ngIf
What is the current behavior?
MatPaginator does not work at all
What are the steps to reproduce?
https://stackblitz.com/edit/angular-8e1csg
What is the use-case or motivation for changing an existing behavior?
The paginator should work within the ngIf
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Angular 6.0.3, Material 6.2.1
Is there anything else we should know?
If I replace the *ngIf="dataSource"
with [style.display]="dataSource ? 'block' : 'none'"
, then the paginator works fine.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
MatPaginator not working in dynamically generated table.
I encountered this issue when I tried to use the mat-table cdk with dynamic data from an api. What worked for me was...
Read more >Angular Material Table Paginator Dynamic Data - StackBlitz
Starter project for Angular apps that exports to the Angular CLI.
Read more >Paginator | Angular Material
When the user interacts with the paginator, a PageEvent will be fired that can be used to update any associated data view.
Read more >mat-paginator length is not working.Not able to set it
I was able to do a pagination API call.And then I had tried to set the length dynamically as well and it worked...
Read more >Adding pagination to the mat-table using mat ... - Angular Wiki
mat-table selector in Angular used to display data in table format. ... Pagination is nothing but dividing the large number of records in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For what it’s worth, I found it easier to move the data table to it’s own component with the loaded data as an
@Input()
- this meant that from the POV for the data table everything was available synchronously, so I didn’t have to change the way the parent component worked.@pfeigl is correct - the
paginator
value is undefined because you have anngIf
. Unfortunately it is part of the mechanics of Angular thatngOnInit
will not catch view children that are contained within anngIf
.