Exclude or include the particular row from the mat-table view

一个人想着一个人 提交于 2020-01-25 07:48:07

问题


I have a material data table like id title description
The data source for my mat-table is represented by dataSource$: Observable<Thing[]>

<mat-table #table [dataSource]="dataSource$ | async">
...
<mat-table>

Based on a dropdown I want to be able to show all the data(the way it works at the moment) but also to hide the items that have description empty and way around hide the items that have description not empty.

I think I have to do that through the custom pipe? or use a .filter() on my observable?
Any thoughts how to aproach that best?

UPDATE:

I am trying to use .filter() but got an issue, have no data displayed with that:

dataSource$ = originalDataSource$.filter((item: any) => item.description == null)

thoughts?


回答1:


For this, you have to maintain original dataSource$ separately like originalDataSource$. Write change event on dropdown like (change)="onChange($event.target.value)" and filter your data in that function like

onChange(value){  
 dataSource$ = originalDataSource$.filter(m =>{ your logic/conditions })
}


来源:https://stackoverflow.com/questions/49935597/exclude-or-include-the-particular-row-from-the-mat-table-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!