Angular MatPaginator not working

前端 未结 30 1627
情歌与酒
情歌与酒 2020-12-04 23:05

I have 2 components. Both have mat-table and paginators and pagination is working for one component and not working for the other component though the code is similar. Below

30条回答
  •  被撕碎了的回忆
    2020-12-04 23:50

    I had the same issue (table data displaying but MatPaginator is not working). In my case, I forgot to create "new MatTableDataSource"

    this.dataSource = somearray;
    

    not enable MatPaginator while this.dataSource = new MatTableDataSource(somearray); does.

    extract from material documentation

    "To simplify the use case of having a table that can sort, paginate, and filter an array of data, the Angular Material library comes with a MatTableDataSource that has already implemented the logic of determining what rows should be rendered according to the current table state."

    hope this answer helps someone.

提交回复
热议问题