Angular Material 2 DataTable Sorting with nested objects

前端 未结 11 889
孤街浪徒
孤街浪徒 2020-11-29 17:25

I have a normal Angular Material 2 DataTable with sort headers. All sort are headers work fine. Except for the one with an object as value. These doesn\'t sort at all.

11条回答
  •  攒了一身酷
    2020-11-29 18:00

    Another alternative, that no one threw out here, flatten the column first...

    yourData.map((d) => 
       d.flattenedName = d.project && d.project.name ? 
                         d.project.name : 
                         'Not Specified');
    
    this.dataSource = new MatTableDataSource(yourData);
    

    Just another alternative, pros and cons for each!

提交回复
热议问题