Mat-table Sorting Demo not Working

后端 未结 20 2795
旧巷少年郎
旧巷少年郎 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:29

    My solution for this problem is as below - 
    
    
    1. These two lines will go in the same order.
    
        this.dataSource = new MatTableDataSource(myRowDataArray);// this dataSource is used in table tag.
        this.dataSource.sort = this.sort;
    
    
    2. Pass MatTableDataSource object in [dataSource] 
        
        // rest of the table definition here
        
    3. By default, the MatTableDataSource sorts with the assumption that the sorted column's name matches the data property name that the column displays. Example - Date {{row.date|date}} 4. If the table is inside *ngIf,then replace it with [hidden] or some other filter.

    I missed the 2nd point.

    Cheers!
    

提交回复
热议问题