从 mat-table 视图中排除或包括特定行



我有一个材料数据表,如id title description
我的mat-table的数据源由dataSource$: Observable<Thing[]>

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

基于下拉列表,我希望能够显示所有数据(目前的工作方式(,但也希望隐藏description空的项目,并隐藏description不为空的项目。

我想我必须通过自定义管道来做到这一点? 还是在我的可观察对象上使用.filter()
有什么想法吗?

更新:

我正在尝试使用.filter()但遇到了问题,没有显示任何数据:

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

思潮?

为此

,您必须像originalDataSource$一样单独维护原始dataSource$。像(change)="onChange($event.target.value)"一样在下拉列表中写入更改事件,并在该函数中过滤数据,例如

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

最新更新