---
title: "Discussion on \"Angular Material Table - custom Sort\" | Hashnode"
description: "Discussion on \"Angular Material Table - custom Sort\". 1. Overview\nAngular Material is most often useful and saves you work a lot building directives and components from scratch, but sometimes we need a little more control over behaviors and events. In this article we'll learn how we can do a custom sort..."
url: "https://hashnode.com/posts/angular-material-table-custom-sort/60202ea00da0382a2d49ddd3"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Angular Material Table - custom Sort](https://alina-olaru.hashnode.dev/angular-material-table-custom-sort?utm_source=hashnode&utm_medium=feed)

1\. Overview Angular Material is most often useful and saves you work a lot building directives and components from scratch, but sometimes we need a little more control over behaviors and events. In this article we'll learn how we can do a custom sort...

Feb 7, 2021 · 9 min read · alina-olaru.hashnode.dev  
Read the article

-   [#angular](https://hashnode.com/tag/angular)
-   [#angularjs](https://hashnode.com/tag/angularjs)
-   [#typescript](https://hashnode.com/tag/typescript)
-   [#frontend-development](https://hashnode.com/tag/frontend-development)
-   [#angular-material](https://hashnode.com/tag/angular-material)

## Written by

[Alina Olaru](https://hashnode.com/@alinaaolaru)

@alinaaolaru

  
[View profile](https://hashnode.com/@alinaaolaru)

## Responses 1

Markdown supported · ⌘↵ to post

[Wellington Domiciano](https://hashnode.com/@wldomiciano)

[Feb 8, 2021](https://hashnode.com/posts/angular-material-table-custom-sort/60202ea00da0382a2d49ddd3/comment/602104d80da0382a2d49ed0a)

Hi, nice article!

To avoid to call `setTimeout()` function inside your `ngOnInit()` method, you can to use the `ngAfterViewInit()` method.

```
ngAfterViewInit() {
  this.dataSource.sort = this.sort;
  this.dataSource.sortingDataAccessor = (item, property) => {
    return item[property].toLocaleLowerCase();
  };
}
```

[According to documentation](https://angular.io/api/core/ViewChild), Angular guarantees that your `@ViewChild` will be set before `ngAfterViewInit()` is called.
