I’m trying to add pagination to my mat-table in Angular 6. I’m using some of the examples in the link below. But it’s not working:
https://material.angular.io/components/table/examples
It looks like the mat-table populates with data properly and the paginator appears underneath it properly, but they’re failing to connect together:
As you can see, the paginator is set to 5 records per page, but there are more than records on the current page in the table. It also says 0 out of 0, which further indicates a failure to link to the table.
Here’s my html:
<mat-table #table [dataSource]="dataSource" class="animate topMatDataTable”>
…
</mat-table>
<mat-paginator [pageSizeOptions]="[5, 10, 20]" [pageSize]="5" showFirstLastButtons></mat-paginator>
Here’s my ts code:
export class DynamicDataListComponent implements OnInit {
…
dataSource : MatTableDataSource<any>;
…
@ViewChild(MatPaginator) paginator : MatPaginator;
…
ngOnInit() {
…
this.loadEndpoints();
}
async loadEndpoints() {
…
const endpointListObs = await this._dataStorageService.getAPIEndpointList();
endpointListObs.subscribe((endpointList: any[]) => {
this.dataSource = new MatTableDataSource<any>(endpointList);
this.dataSource.paginator = this.paginator;
…
});
…
}
…
}
Can anyone tell what I’m doing wrong?
Thanks.