---
title: "Comment by Wellington Domiciano on \"Angular Material Table - custom Sort\" | Hashnode"
description: "Hi, nice article! To avoid to call setTimeout() function inside your ngOnInit() method, you can to use the ngAfterViewInit() method. ngAfterViewInit() { this .d"
url: "https://hashnode.com/posts/angular-material-table-custom-sort/60202ea00da0382a2d49ddd3/comment/602104d80da0382a2d49ed0a"
---

[Discussion](https://hashnode.com/posts/angular-material-table-custom-sort/60202ea00da0382a2d49ddd3)

Comment [Angular Material Table - custom Sort](https://hashnode.com/posts/angular-material-table-custom-sort/60202ea00da0382a2d49ddd3)

[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.
