[英]Filter Angular Material Table with Dropdown
我创建了一个 angular 表,我想根据特定列应用过滤器。 我已经用 mat-options 定义了 mat-select 但问题是当我从下拉数据中的 select 消失并且没有过滤器时。
这是我的标记
<div class="col-sm-4 col-md-4">
<mat-form-field >
<mat-select [(value)]="filterValue" placeholder="Type">
<mat-option *ngFor="let type of types" [value]="type" (click)="applyFilter(type)">
{{type}}
</mat-option>
</mat-select>
</mat-form-field>
</div>
在我写的打字稿中
types = ["All", "Income","Expense"]
applyFilter(filterValue: string) {
this.dataSource.filter = filterValue.trim().toLowerCase();
}
在这里我想过滤类型列(收入和费用)
尝试这个
<div class="col-sm-4 col-md-4">
<mat-form-field >
<mat-select [(value)]="filterValue" placeholder="Type" (click)="applyFilter($event)">
<mat-option *ngFor="let type of types" [value]="type" >
{{type}}
</mat-option>
</mat-select>
</mat-form-field>
</div>
和
applyFilter(event) {
this.dataSource.filter = event.value.toLowerCase();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.