【发布时间】:2020-08-18 16:36:44
【问题描述】:
我正在尝试过滤每个列标题中下拉值的角度垫表。我可以过滤任何一个下拉值,但不能过滤多个下拉值。是否可以在多个下拉列表中?这是我尝试过的..
HTML
<table mat-table [dataSource]="listData">
<ng-container matColumnDef="Name">
<th mat-header-cell *matHeaderCellDef>Name
<br>
<mat-form-field>
<select matNativeControl (change)="onChangeName($event.target.value)">
<option *ngFor="let name of names" [value]="name">
{{name | titlecase}}
</option>
</select>
</mat-form-field>
</th>
<td mat-cell *matCellDef="let row; let rowIndex = index" >
{{row.name}}
</td>
</ng-container>
<ng-container matColumnDef="location ">
<th mat-header-cell *matHeaderCellDef>Location
<mat-form-field>
<select matNativeControl (change)="onChangeLocation($event.target.value)">
<option *ngFor="let location of locations" [value]="location">
{{track | titlecase}}
</option>
</select>
</mat-form-field>
</th>
<td mat-cell *matCellDef="let row; let rowIndex = index" >
{{row.location}}
</td>
</ng-container>
</table>
TS 文件
ngOnInit(): void {
this.listData=new MatTableDataSource(res);
}
onChangeName(name){
this.selectedName=name;
if(this.selectedLocation){
this.listData.filter=name+this.selectedLocation;
}
else{
this.listData.filter=name;
}
}
onChangeLocation(location){
this.selectedLocation=location;
if(this.selectedName){
this.listData.filter=location+this.selectedName;
}
else{
this.listData.filter=location;
}
【问题讨论】:
标签: angular-material mat-table