使用角度过滤来过滤“角度材料表"中的特定列? [英] Filtering specific column in Angular Material Table with filtering in angular?
问题描述
我正在使用 mat-table .它有一个工作正常的过滤器.
I am using mat-table. It has a filter which works fine.
针对下面的数据(所有列)进行了过滤
Filter happened against this below data (All columns)
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"
列的过滤器.我已经看过这个示例,但是过滤Angular中的特定列材质表以角度5 .
But Now I am trying to change the filter because I want is filter just for "position", "name", "symbol"
column. I have gone through this example but Filtering specific column in Angular Material table in angular 5.
我不明白,请为此提供帮助
I did not understand please help me on this
推荐答案
您必须覆盖dataSource的filterPredicate
.
You have to override the filterPredicate
of your dataSource.
以下是操作方法示例:工作演示
Here's an example of how to do it: Working demo
本质上,您想指定过滤器将数据应用于哪些属性:
Essentially, you want to specify what properties in your data the filter is applied to:
this.dataSource.filterPredicate = function(data, filter: string): boolean {
return data.name.toLowerCase().includes(filter) || data.symbol.toLowerCase().includes(filter) || data.position.toString().includes(filter);
};
这篇关于使用角度过滤来过滤“角度材料表"中的特定列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!