【发布时间】:2023-03-10 10:34:01
【问题描述】:
我在 Mat-Table 中介绍了两个案例。如果没有数据,用户会看到 No Data Found,如果他应该在过滤器中搜索 Not Data Found 应该被隐藏并替换为输入的文本。你知道这是怎么回事吗?
我的代码:
// Filter input
<input matInput #filter (keyup)="applyFilter($event.target.value)" placeholder="Durchsuchen" />
<!-- Triggered by the filter -->
<div class="no-search-results" [hidden]="isTableHasData">
<p>Du hast nach <span class="filter-value">"{{ filter.value }}"</span> gesucht. Wir haben leider keine Ergebnisse gefunden.</p>
</div>
<!-- Triggered because there is no data in the backend -->
<div class="no-data" *ngIf="dataSource !== null && dataSource.data !== null && dataSource.data.length === 0">
<p>No Data Found</p>
</div>
// TS
public applyFilter(filterValue: string) {
filterValue = filterValue.trim();
filterValue = filterValue.toLowerCase();
this.dataSource.filter = filterValue;
if (this.dataSource.filteredData.length > 0) {
this.isTableHasData = true;
} else {
this.isTableHasData = false;
}
}
``
【问题讨论】:
-
你当前的代码有什么输出?
-
在当前代码中,过滤时会显示第一个 div 中的文本。这也是正确的。不幸的是,我还看到了第二个 div 中的文本。我该如何隐藏它?
标签: javascript angular typescript mat-table