components icon indicating copy to clipboard operation
components copied to clipboard

mat-sort-header not working when using ng-content

Open frikkievb opened this issue 8 years ago • 4 comments

Bug, feature request, or proposal:

When including content for a table using ng-content - the mat-sort-header is not working.

What is the expected behavior?

Mat-sort-header to be working when including row definitions via ng-content.

What is the current behavior?

Rows are rendered with ng-content but the sorting is not working.

What are the steps to reproduce?

Providing a StackBlitz reproduction is the best way to share your issue.
StackBlitz starter: https://angular-klhdhh.stackblitz.io

https://stackblitz.com/edit/angular-klhdhh

What is the use-case or motivation for changing an existing behavior?

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

"@angular/animations": "^5.2.2", "@angular/cdk": "^5.2.2", "@angular/common": "^5.2.2", "@angular/compiler": "^5.2.2", "@angular/core": "^5.2.2", "@angular/flex-layout": "^2.0.0-beta.12", "@angular/forms": "^5.2.2", "@angular/http": "^5.2.2", "@angular/material": "^5.2.2", "@angular/platform-browser": "^5.2.2", "@angular/platform-browser-dynamic": "^5.2.2", "@angular/router": "^5.2.2", "typescript": "~2.4.2" "@angular/cli": "^1.6.3", "@angular/compiler-cli": "^5.2.2",

Is there anything else we should know?

frikkievb avatar Mar 16 '18 07:03 frikkievb

Hi, hope you are well. Is there any feedback on this problem maybe? :)

frikkievb avatar Mar 26 '18 07:03 frikkievb

In your example, there are two instances of MatSort. The app component had one on the grid, which was being registered to by the sort header. The table had its own sort that was connected to the data source but was not registered to.

To resolve this, only have one MatSort: https://stackblitz.com/edit/angular-vze9r3?file=app/ics-module/ics-datagrid.component.ts

I changed it so that the data source is provided the sort through ContentChild

andrewseguin avatar Mar 27 '18 18:03 andrewseguin

Thank you very much. I missed that.

frikkievb avatar Mar 28 '18 10:03 frikkievb

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.