从垫子表格视图中排除或包括特定行 [英] Exclude or include the particular row from the mat-table view
问题描述
我有一个物料数据表,如id
title
description
我的mat-table
的数据源由dataSource$: Observable<Thing[]>
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>
基于一个下拉菜单,我希望能够显示所有数据(当前的工作方式),而且还可以隐藏description
为空的项目,并且可以隐藏description
为空的项目空的.
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.
我想我必须通过自定义管道来做到这一点?或在我的观察对象上使用.filter()
?
有什么想法可以最好地建议吗?
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?
更新:
我正在尝试使用.filter()
,但出现问题,没有显示任何数据:
I am trying to use .filter()
but got an issue, have no data displayed with that:
dataSource$ = originalDataSource$.filter((item: any) => item.description == null)
有想法吗?
推荐答案
为此,您必须像originalDataSource$
一样分别维护原始的dataSource$
.在下拉菜单中写入更改事件,例如(change)="onChange($event.target.value)"
并在函数中过滤数据,例如
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 })
}
这篇关于从垫子表格视图中排除或包括特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!