gpt4 book ai didi

angular - 使用 Angular 过滤过滤 Angular Material 表中的特定列?

转载 作者:太空狗 更新时间:2023-10-29 17:00:58 24 4
gpt4 key购买 nike

我正在使用 mat-table .它有一个过滤器,效果很好。

针对以下数据(所有列)进行过滤

const ELEMENT_DATA: Element[] = [
{position: 14598, name: 'Hydrogen', weight: 1.0079, symbol: 'H'},
{position: 24220, name: 'Helium', weight: 4.0026, symbol: 'He'},
{position: 39635, name: 'Lithium', weight: 6.941, symbol: 'Li'},
{position: 42027, name: 'Beryllium', weight: 9.0122, symbol: 'Be'},
{position: 53216, name: 'Boron', weight: 10.811, symbol: 'B'},
{position: 60987, name: 'Carbon', weight: 12.0107, symbol: 'C'},
{position: 70976, name: 'Nitrogen', weight: 14.0067, symbol: 'N'},
{position: 81297, name: 'Oxygen', weight: 15.9994, symbol: 'O'},
{position: 90975, name: 'Fluorine', weight: 18.9984, symbol: 'F'},
{position: 18879, name: 'Neon', weight: 20.1797, symbol: 'Ne'},
{position: 11209, name: 'Sodium', weight: 22.9897, symbol: 'Na'}

];

但现在我正在尝试更改过滤器,因为我想要的是仅针对 "position"、"name"、"symbol" 列的过滤器。我已经完成了这个例子但是Filtering specific column in Angular Material table in angular 5 .

我不明白请帮助我

StackBlitz Code

最佳答案

您必须覆盖数据源的 filterPredicate

这是一个如何做到这一点的例子:Working demo


本质上,您想要指定过滤器应用于数据中的哪些属性:

this.dataSource.filterPredicate = function(data, filter: string): boolean {
return data.name.toLowerCase().includes(filter) || data.symbol.toLowerCase().includes(filter) || data.position.toString().includes(filter);
};

关于angular - 使用 Angular 过滤过滤 Angular Material 表中的特定列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49939979/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com