答案 0 :(得分:1)
您的数据源中有一个名为filteredData
的属性。应用过滤器后,filteredData
将使用最新的数据列表进行更新。因此,您只需检查dataSource.filteredData
的长度并确定要显示或隐藏的内容即可。
我创建了一个stackblitz。你可以看看这个。
答案 1 :(得分:0)
您可以检查dataSource.filteredData
列表的长度,然后在表内显示“找不到内容”消息:
HTML:
<mat-form-field>
<input matInput [formControl]="nameFilter" placeholder="Filter 1 (working sample)">
</mat-form-field>
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
<!-- Position Column -->
<ng-container matColumnDef="position">
<th mat-header-cell *matHeaderCellDef> No.
<div>
<mat-form-field>
<input matInput class="form-field" [formControl]="positionFilter" placeholder="Postion Filter">
</mat-form-field>
</div>
</th>
<td mat-cell *matCellDef="let element"> {{element.id}} </td>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef> Name
<div>
<mat-form-field>
<input matInput class="form-field" [formControl]="nameFilter" placeholder="Name Filter">
</mat-form-field>
</div>
</th>
<td mat-cell *matCellDef="let element"> {{element.name}} </td>
</ng-container>
<!-- Weight Column -->
<ng-container matColumnDef="weight">
<th mat-header-cell *matHeaderCellDef> Weight </th>
<td mat-cell *matCellDef="let element"> {{element.weight}} </td>
</ng-container>
<!-- Symbol Column -->
<ng-container matColumnDef="symbol">
<th mat-header-cell *matHeaderCellDef> Symbol </th>
<td mat-cell *matCellDef="let element"> {{element.symbol}} </td>
</ng-container>
<ng-container matColumnDef="isDataAvailable">
<mat-footer-cell *matFooterCellDef colspan="6">
No Data found
</mat-footer-cell>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
<mat-footer-row *matFooterRowDef="['isDataAvailable']" [ngClass]="{'hide':!(dataSource.filteredData!=null && dataSource.filteredData.length==0)}">
</mat-footer-row>
</table>