question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Table] Throw error if MatSortModule is not imported while using "MatSort/matSort"

See original GitHub issue

Bug, feature request, or proposal

Proposal

What is the expected behavior?

Using @ViewChild(MatSort) sort: MatSort; and <mat-table [dataSource]="dataSource" matSort> without import { MatSortModule } from '@angular/material'; will throw an error like some other material component (if i remember it’s something like “you need to import xxxx…”)

What is the current behavior?

Nothing, the sorting arrows are just not displayed (and sorting doesn’t work)

What are the steps to reproduce?

Just remove the MatSortModule : https://stackblitz.com/angular/voqnaoexppp?file=main.ts

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

I lost many hours on this… i take some code from my stackblitz to my main project and continue developping, but after a moment i see sorting doesn’t work anymore without errors in the console… I search, scratch my head, and finally reverse my code to the beginning but still not working !

Finally i found solution online, import MatSortModule… so depressing 😦

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

Latest

Is there anything else we should know?

I know it’s my fault, but without error it’s difficult to find this.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:19 (2 by maintainers)

github_iconTop GitHub Comments

119reactions
razvanmcommented, Aug 2, 2018

In came here because I hit the error @tzachs reported above:

ERROR Error: Uncaught (in promise): HierarchyRequestError: Failed to execute 'appendChild' on 'Node': This node type does not support this method.

In my case the issues was that, by accident, I was placing the mat-sort-header inside the ng-container that preceded the th where was suppose to go.

14reactions
jayricxcommented, Sep 19, 2018

@razvanm, you save me much time. after reading your comment, I checked my code and found that I did exactly the same and accidentally placed the mat-sort-header in the ng-container.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MatSort not working. Throws Error: MatSortHeader must be ...
Add the matSort directive to the table and add mat-sort-header to each column header, as described in other questions. Import MatSortModule: ...
Read more >
Sort header - Angular Material
Applies sorting behavior (click to change sort) and styles to an element, including an arrow to display the current sort direction. Must be...
Read more >
Angular 5 Material Table with Sortable Headers - YouTube
Donate us:http://paypal.me/tipawaisAngular 5 Materials are great way to generate interacting UI using any data. Tables in angular material ...
Read more >
Angular Material Table, Filtering, Sorting, Paging - Code Maze
In this article we are going to learn about Angular Material Table and its functionalities related to Filtering, Sorting and Paging.
Read more >
Angular mat-table sort example: Adding sorting to the material ...
With the help of MatSortModule we can add sorting to mat-table in Angular. MatSortModule is separate component in Angular material and we have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found