-
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
Table Sorting Is Not working when content is in a div with *ngIf #14843
Comments
This is because the You'll need to set the sort after the view has been initialized to resolve this: ngAfterViewInit() {
this.dataSource.sort = this.sort;
} https://stackblitz.com/edit/angular-quzvjv-zi9x3z?file=app/table-sorting-example.ts |
@andrewseguin, thank you for the very quick reply and your assistance. FWIW, your solution work when the *ngIf evaluated to true immediately. However, when it was actually conditional I still have the same problem. However, with the insight you provided I was able to realize my root cause is that the @ViewChild was initialized. I followed the advice from https://stackoverflow.com/questions/39366981/angular-2-viewchild-in-ngif and was able to resolve my issue. My working solution is at: https://stackblitz.com/edit/angular-quzvjv-jzdbb6 Thanks! |
Just ran into the same issue with the table in an <ng-container *ngIf=...>. @TomJahncke, your solution worked for me. Thanks. @andrewseguin, would be helpful if an error was thrown rather than having it fail silently. And maybe set up the examples with the following:
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
What is the expected behavior?
Table data is sorted when header is clicked
What is the current behavior?
The header gets the sort arrow but no data is sorted.
What are the steps to reproduce?
This was built from the Angular Material Table example on sorting (https://material.angular.io/components/table/overview#sorting). Just added an outer <div *ngIf="ture"> ...
Example of the broken behavior is at:
https://stackblitz.com/edit/angular-quzvjv?file=app%2Ftable-sorting-example.html
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Angular - 7.2.0
Angular Material - 7.2.1
TypeScript - 3.1.1
OS - Mac 10.14.2
Browser - Chrome 71 / Safari 12
Is there anything else we should know?
The text was updated successfully, but these errors were encountered: