我正在尝试使用角度材料表过滤所有列。还有一个搜索过滤所有。当我尝试通过过滤使用搜索和列时,会导致filterPredicate
出现问题。
这是我的实现方式
...
_filter:{};
ngOnInit() {
//it needs to column by filter but causing a problem with using global filter
this.dataSource.filterPredicate = (data: User, filters: string) => {
debugger;
const parsedFilters = JSON.parse(filters);
return Object.keys(parsedFilters)
.map(column => {
return data[column].toLocaleString().trim().toLocaleLowerCase().includes(parsedFilters[column].toLocaleString().trim().toLocaleLowerCase())
})
.reduce((acc: boolean, curr: boolean) => (acc = curr) && acc, true);
}
}
//global filter
public doFilter = (value: string) => {
this.dataSource.filter = value.trim().toLocaleLowerCase();
}
//column by filter
public applyFilter(filterValue: string, column: string) {
this._filter = {
...this._filter,
[column]: filterValue
};
if (!filterValue) delete this._filter[column];
this.dataSource.filter = JSON.stringify(this._filter);
this.fullSearch = false;
}
...
我该如何解决。 谢谢