簡體   English   中英

過濾 Angular 材料表與下拉

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM