Angular Material 2 DataSource filter with nested object

前端 未结 3 1225
无人共我
无人共我 2020-12-28 15:14

I have angular 4 project with material 2, I want to filter the data in MatTable. DataSource filter is working fine when we filter data on field which are not nested.

<
3条回答
  •  孤独总比滥情好
    2020-12-28 15:25

    This is a very generic solution and will work for sure. It does not depends on the structure of json, be it simple or nested, this solution works for all.

    this.dataSource.filterPredicate = (data: any, filter) => { const dataStr =JSON.stringify(data).toLowerCase(); return dataStr.indexOf(filter) != -1; }

提交回复
热议问题