Mat-table sorting not working without setTimeout - this.sort is undefined

Discussão em 'Angular' iniciado por Silver Origami, Fevereiro 18, 2025.

  1. I have a table where data and columns are changed dynamically. I think I need to update the sort, but when I do this:


    this.sort is undefined
    ​

    Setting setTimeout to 2 seconds helps, but I know it's a bad solution. How can I fix it properly?

    @ViewChild(MatSort, { static: false }) sort: MatSort;

    ...

    this._service.GetData(this.id, this.filteredData)
    .subscribe(res => {
    setTimeout(() => this.dataSource.sort = this.sort, 2000);
    }

    Continue reading...

Compartilhe esta Página