Mat-table Sorting Demo not Working

后端 未结 20 2719
旧巷少年郎
旧巷少年郎 2020-12-02 10:55

I am trying to get the mat-table sorting to work locally, and while I can get the data to show up as expected, clicking on the header row does not do the sortin

20条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 11:19

    I found multiple answers to this question, but implementing them individually did not give me any results. So I tried to merge answers and it worked.

    Firstly, I added ViewChild sort inside NgAfterViewInit interface. (It was initially inside a function that was called through NgOnInit

     ngAfterViewInit(){
        this.tableData.sort = this.sort;
      }
    

    For the second step i changed the *ngIf inside a container to [hidden]. I do get an error that says that the value is not loaded. But it is not a major one to be concerned about till now.

    before

    after

    psst.. You can also consider adding a loading spinner while your table is being loaded through mat-footer to above the above bs.

        
                        
                            

提交回复
热议问题