I'm using Mart Sort Header component from Angular Material.
This is my async function to get data.
//DataSource variable
dataSource: MatTableDataSource<any[]> = new MatTableDataSource([] as any[])
getUsers() {
this.loading = true
this.authService
.getAllUsersData()
.then((users: any[]) => {
this.dataSource = new MatTableDataSource(users)
console.log('datasrc', this.dataSource.data)
this.dataSource.sort = this.sort
this.loading = false
})
.catch((error) => {
this._snackBar.open(error, 'Close', {
duration: this.SNACKBAR_DURATION
})
this.loading = false
})
}
I call this function in my NgOnInit function:
ngOnInit(): void {
this.getUsers()
}
The data is printed correctly into the Mat Table but if I click on the arrows of the data table to sort it nothing happens. No error is printed to the console.
I tried writing the getUsers function in the NgAfterViewInit() function I tried writing this.dataSource.sort = this.sort in the NgAfterViewInit() function (only there and I also tried writing it in both places).
I just want to be able to sort my data table.