I have an Angular 7 application with Mat Tables retrieving data from API. I have assigned dynamic pagination values, that is pageSizeOptions value will be getting changed whenever I load grid based on some dropdown value and by default all the records will be getting displayed.
If API returns 23 records, then pageSizeOptions will have 10,20,23,30,40,50 and by default it will display all 23 records. When next time I change dropdown value, API returns 45 records but this time still my grid displays only 23 records eventhough pageSizeOptions has 10,20,30,40,45,50 and selection shows 45 as selected.
I assume this is due to View/Grid loaded before pageSizeOptions value is assigned since API takes some time to return data. I thought of resolving this issue by implementing Observable/subscribe.
I am not sure, how to implement these for pageSizeOptions. Can someone please help me to resolve this.
let gridData = responseStudents.Students.map(item => new ResponseStudents());
this.myDataSource = new MatTableDataSource(gridData);
this.Count = gridData.length;
this.PageSizeOptions = [this.Count, 5, 10, 25, 100, 500];
//To remove duplicate
this.PageSizeOptions = Array.from(this.PageSizeOptions.reduce((m, t) => m.set(t, t), new Map()).values());
MatTableDataSource
for binding data to mat-table? Can you please add the code where you assign results of API call to mat-table data? And also can you please add the template code format-table
? – ysf