【发布时间】:2019-09-06 05:18:42
【问题描述】:
嘿,我正在尝试创建一个搜索栏,当我输入超过 3 个字符时,它只显示已过滤的表格lastname,(条件为空)
这里是 HTML
<mat-form-field>
<input matInput id="search-field" (keyup)="applyFilter($event.target.value)" placeholder="Search">
</mat-form-field>
<a [routerLink]='["/doctors/new"]' class="doctors-list-newDoctor-button">
<button mat-raised-button id="doctors-list-newDoctor-button">
<i class="material-icons">
add
</i>
</button>
</a>
<div>
<table mat-table matSort [dataSource]="this.displayedDoctors" id="doctors-list-table" (matSortChange)="sortData($event)" class="mat-elevation-z8">
<ng-container matColumnDef="lastName">
<th mat-header-cell *matHeaderCellDef mat-sort-header id="doctors-
list-lastName-header">lastName</th>
<td mat-cell *matCellDef="let doctor" class="doctor-lastName">
{{doctor.lastName}}</td>
</ng-container>
<ng-container matColumnDef="firstName">
<th mat-header-cell *matHeaderCellDef id="doctors-list-firstName-
header">firstName</th>
<td mat-cell *matCellDef="let doctor" class="doctor-firstName">
{{doctor.firstName}}</td>
</ng-container>
<ng-container matColumnDef="format">
<th mat-header-cell *matHeaderCellDef id="doctors-list-format-
header">format</th>
<td mat-cell *matCellDef="let doctor" class="doctor-inami">
{{doctor.format}}</td>
</ng-container>
<ng-container matColumnDef="inami">
<th mat-header-cell *matHeaderCellDef id="doctors-list-inami-
header">inami</th>
<td mat-cell *matCellDef="let doctor" class="doctor-format">
{{doctor.inami}}</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="DoctorsListHeaders"></tr>
<tr mat-row *matRowDef="let row; columns: DoctorsListHeaders;" (click)="OpenDoctor(row)"></tr>
</table>
</div>
这里是模型
export interface Doctor {
lastName: string;
firstName: string;
format: string;
inami: string;
_id: string;
}
export const EMPTY_DOCTOR: Doctor = {
lastName: null,
firstName: null,
format: null,
inami: null,
_id: null
}
这里是打字稿
applyFilter(filterValue: string) {
this.filterSearch = filterValue.toLowerCase();
this.doctorsService.getAll({ lastName: this.filterSearch, inami: this.filterSearch }).subscribe((doctors: Doctor[]) => {
//this.dataDoctors = doctors;
this.displayedDoctors.data = this.dataDoctors;
if (this.filterSearch.length >= 3) {
}
if (this.tableSort) {
this.sortData(this.tableSort);
}
});
}
【问题讨论】:
-
那么这里有什么问题?
-
你有什么问题?
-
我的问题是,当我在过滤栏上输入超过 3 个字符时,如何创建一个显示数据的条件
-
请提供
html代码。 -
@M.Ela Okey,你想展示什么数据?是
displayedDoctors.data吗?