如何过滤具有特定列的材料数据表?
public dataSource;
this.dataSource = new MatTableDataSource(this.items);
this.dataSource.filterPredicate = function customFilter(data , filter:string ): boolean {
return (data.name.startsWith(filter));
}
applyFilter(filterValue: string) {
filterValue = filterValue.trim(); // Remove whitespace
filterValue = filterValue.toLowerCase(); // MatTableDataSource defaults to lowercase matches
this.dataSource.filter = filterValue;
}
上面的代码不起作用,当我键入返回时,没有匹配的数据。
原文由 bereket gebredingle 发布,翻译遵循 CC BY-SA 4.0 许可协议
从 文档。
如果您只想使用过滤器特定的列,您需要覆盖
filterPredicate
并且答案已经在 这里。这是过滤的工作示例。
表过滤-example.html
表过滤-example.ts
您可以使用 filterPredicate 过滤特定列,如下所示:
我已经更改了
applyFilter()
并添加了ngOnInit()
。现在它只工作 名称 列和完全相同的值(==)