-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug(mat-table): MatTable with observable as data source should trigger change detection after update #24483
Comments
Your example is using |
@crisbeto I checked the CDK source, there is nothing to trigger change detection. That is why the observable source also important, no data binding change is happening, so if internally the table does not mark itself for check, then nothing will. |
Hello, It seems like the issue is that the
I'll go ahead and close this because MatTable appears to be works as expected when Best, |
I thought this trackBy works the same way as the ngFor, meaning that it is used to identity check (if DOM element needs to be moved, created, deleted). If identity matches then bindings are updated, but DOM hierarchy does not change. |
@zarend from the updated example (https://stackblitz.com/edit/components-issue-5pt19s) it can clearly be seen, that tracking by value destroys and recreates the rows and their component tree (see the console logs). So changing the trackBy is not the solution (Track by function is meant to provide identity anyway), Please reopen the bug. |
The solution is probably only one line of code, that - if the data source is an observable - runs a markForCheck on the table. |
Thanks for the reproduction showing the issue - something does seem off because I would have expected the table to update on each push on the datasource stream. |
It is very simple:
changedetection will not be triggered and |
This also prevents the rendering of components inside a MatNoDataRow, even without any trackBy function. I have updated the example to show this: https://stackblitz.com/edit/components-issue-dpw4qc As a workaround I currently call markForCheck inside the constructor of components that I plan to use inside a MatNoDataRow. |
Is this a regression?
The previous version in which this bug was not present was
No response
Description
MatTable with an observable as data source does update viewRefs, but does not trigger a detection change (markForCheck).
Which can cause the view not to update (until a change detection is triggered by some other event)
Reproduction
Steps to reproduce:
https://stackblitz.com/edit/components-issue-5pt19s
Expected Behavior
MatTable with observable as data source should mark itself for checking (markForCheck) when viewRefs were updated.
Actual Behavior
No change detection triggered.
Environment
The text was updated successfully, but these errors were encountered: