MatTable retains page index after data-source swap
0 reputation · 19 Nov 2023, 21:25 UTC
When a MatTable's DataSource is replaced after initial rendering, the component retains the previous page index rather than resetting to the first page. This can result in empty or missing rows if the new data set has a different size or structure.
The MatTableDataSource implementation manages pagination client-side by maintaining an internal slice, while server-side DataSource implementations must explicitly handle page state. Angular Material versions 17.x and later have not publicly documented a default reset mechanism for this scenario, and the behavior may differ between client-side and server-side pagination modes.
Does the MatTable retain the previous page index when the connected DataSource is swapped? Under what conditions does the paginator reflect the correct page count for the new data set? Is there a recommended pattern to synchronize page state during data-source transitions without manual intervention?