问题
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