I have no problem in adding sorting and pagination to predefined tables like this:
@ViewChild('myTableSort') myTableSort:MatSort;
@ViewChild('myTablePaginator') myTablePaginator:MatPaginator;
then after getting table data:
this.tableData = new MatTableDataSource(data);
this.tableData.sort = this.myTableSort;
this.tableData.paginator = this.myTablePaginator;
This works fine but when I have an unknown number of tables, I need to programmatically add a paginator and sort to each table.
Can I somehow declare a new paginator myTablePaginator2
after getting table data?
How can I add a paginator and sort dynamically after creating tables?
I had a similar situation where I needed to loop through records from an API response then create 2 tables with sorting for each record. I solved this with a QueryList
HTML