question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MatPaginator does not work with dynamic data

See original GitHub issue

Bug, 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:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
studdscommented, Jun 13, 2018

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.

2reactions
andrewseguincommented, Jun 7, 2018

@pfeigl is correct - the paginator value is undefined because you have an ngIf. Unfortunately it is part of the mechanics of Angular that ngOnInit will not catch view children that are contained within an ngIf.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found