Getting this wired without the weird bugs
I always think MatPaginator and MatSort should be easy. You drop them in, you point your table at them, done. Then it hits. The sort arrows show up but nothing moves. Or the paginator says “0 of 0” while the rows are clearly there. That’s when I stop and look at the wiring, not the HTML.
The big thing is timing. ViewChild is real picky. If you grab paginator and sort too early, they exist in your head but not in the view yet. So you assign them and it silently does nothing. Then later you load data from an API, replace the dataSource, and boom, you just threw away the paginator and sort references you set before.
What i’m actually trying to do
I want a table where sorting works every time, pagination updates right away, and I don’t have to click around to “wake it up”. So I keep it simple. Use MatTableDataSource, wait until AfterViewInit to connect ViewChild stuff, and if data arrives later I update dataSource.data instead of creating a brand new data source unless I really need to.
And yeah there are gotchas that feel dumb once you see them. Like forgetting to import MatSortModule. Or using server side paging but still expecting MatPaginator to slice rows for you like magic.
Quick ending
If I wire paginator and sort at the right moment, and I don’t accidentally replace my dataSource after that, everything starts behaving like it should.