如果材料表角度中的过滤器无结果,如何显示“无记录”

Vya*_*ddy 6 javascript typescript angular-material angular

如果有人搜索当前表显示空数据,我想添加“无记录消息”!

以下是angular js中示例材料表的链接 https://material.angular.io/components/table/examples

Vya*_*ddy 5

我找到了确切的解决方案

在打字稿中:

applyFilter(filterValue: string) {
 filterValue = filterValue.trim(); // Remove whitespace
 filterValue = filterValue.toLowerCase(); // MatTableDataSource defaults to lowercase matches
 this.dataSource.filter = filterValue;
 if(this.dataSource.filteredData.length==0){
   this.displayNoRecords=true;
 }else{
   this.displayNoRecords=false;

 }
}
Run Code Online (Sandbox Code Playgroud)

在模板中

<mat-card  *ngIf="displayNoRecords" style="padding:100px;">
  <h3 style="text-align:center">We couldn't find data for 
 <span style="color:red">"{{dataSource.filter}}"</span><br>
Make sure the label,type or status are spelled and formatted correctly
</h3>
</mat-card>
Run Code Online (Sandbox Code Playgroud)


sai*_*aif 0

您可以使用 ng-if 来检查条件 <table ng-if="data==null" > <tr > <td colspan="numberofcolum"> No Records </td></tr> </table>