Angular MatPaginator not working

前端 未结 30 1641
情歌与酒
情歌与酒 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:46

    To paginate the table's data, add a after the table.

    If you are using the MatTableDataSource for your table's data source, simply provide the MatPaginator to your data source. It will automatically listen for page changes made by the user and send the right paged data to the table.

    Otherwise if you are implementing the logic to paginate your data, you will want to listen to the paginator's (page) output and pass the right slice of data to your table.

    For more information on using and configuring the , check out the mat-paginator docs.

    The MatPaginator is one provided solution to paginating your table's data, but it is not the only option. In fact, the table can work with any custom pagination UI or strategy since the MatTable and its interface is not tied to any one specific implementation.

    @ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;
    ngOnInit() {
      this.dataSource.paginator = this.paginator;
    }
    

    See also https://material.angular.io/components/table/overview

提交回复
热议问题