【发布时间】:2018-07-28 18:12:24
【问题描述】:
我正在使用Angular Material Data Table 并尝试对所有值进行过滤。 我注意到的是,当使用 MatTableDataSource 时,过滤器仅搜索通过的实体的顶层,如果实体附加了相关记录,则不会搜索它。
是否可以控制过滤器搜索的深度并使其能够搜索附加的相关实体?
编辑 1 个由原理图生成的示例代码:
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
@Input() dataSource: MatTableDataSource<TestEntity>;
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns = ['id', 'name', 'view_related_child'];
ngOnInit() {
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
applyFilter(filterValue: string) {
filterValue = filterValue.trim(); // Remove whitespace
filterValue = filterValue.toLowerCase(); // MatTableDataSource defaults to lowercase matches
this.dataSource.filter = filterValue;
}
编辑 2 个实体:
export class TestEntity {
id: string;
name: string;
childEntity: ChildEntity;
}
export class ChildEntity {
childId: string;
childName: string;
childDate: string;
}
【问题讨论】:
-
你检查过这个question吗?
-
@fatemefazli am now,在我最初的搜索中没有弹出
-
你能提供一些代码或stackblitz吗?
-
@fatemefazli 当然,但在这个阶段不会有太大帮助,使用原理图生成表格,所以它非常粗略。
-
@fatemefazli 基本上我也希望能够按实体子数据过滤