I have a mat-table that might show up to 100 entries per page. At first, I had one mat-paginator at the bottom that worked fine. Now I'm being asked to set a paginator at the top and another one at the bottom of the table, so the user won't have to scroll all the way down to reach the paginator if they are looking for an entry that is at the top.
The thing is that both paginators must be linked to the same data source.
I´ve tried giving a different id for each one, using ViewChild to get them and assign them to the same data source, but it only works with one of them.
main.component.ts:
flights: Flight[] =[];
dataSource = new MatTableDataSource<Flight>(this.flights);
@ViewChild('PAGINATOR') paginator: MatPaginator;
@ViewChild('OTROPAGINATOR') paginatorOtro: MatPaginator;
main.component.html:
<mat-paginator #PAGINATOR (page)="pageEvent = handlePage($event)"
[length]="length" [pageSizeOptions]="[25, 50, 100]" showFirstLastButtons>
</mat-paginator>
<table mat-table ...> ... </table>
<mat-paginator #OTROPAGINATOR (page)="pageEvent = handlePage($event)"
[length]="length" [pageSizeOptions]="[25, 50, 100]" showFirstLastButtons>
</mat-paginator>
Linking paginators to data source:
this.dataSource = new MatTableDataSource<Flight>(this.flights);
this.dataSource.paginator = this.paginator;
this.dataSource.paginator = this.paginatorOtro;
Could someone guide me with this, please?