[英]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.