feat(MatTable & MatSort): Ability to track sorting events inside wrapper table component #28903
Labels
feature
This issue represents a new feature or feature request rather than a bug or bug fix
needs triage
This issue needs to be triaged by the team
Feature Description
Allow listening to sort events in the table-wrapping components.
Use Case
I have a custom TableComponent wrapping
<mat-table>
functionality.Here's a little sample from
table.component.html
:As of now, hosts components add
matSort
directive and listen to(matSortChange)
event:which creates duplication of a code like this:
because all our host components handle sorting the same way - they trigger a Subject which triggers an API call.
I want to move some of the logic into the TableComponent to simplify the usage. So I want to pass an object full of subjects (searching$, sorting$, paging$, etc.) to the TableComponent and make it react to sort events on its own like so:
However, if I don't add matSort to the host component, I'll get
MatSortHeader must be placed within a parent element with the MatSort directive
error. And if I do, it'll seem to ignore the matSort set in the TableComponent.Here's a working example on Stackblitz. Try to sort and notice that TableComponent doesn't get notified about it.
The text was updated successfully, but these errors were encountered: