[英]filterPredicate from material table was not working in angular app
我想為我的材料表實現一個客戶過濾器,但是當我調試並在此客戶過濾器 function 中設置斷點時,它不起作用。
代碼是這樣的:
ngOnInit() {
if (
!this.displayedColumns &&
this.tableData.rows.length > 0 &&
!this.isFilterAvailable
) {
this.displayedColumns = _.keys(_.first(this.tableData.rows));
} else {
this.dataSource.data = this.tableData.rows;
this.initFilterValues(_.keys(_.first(this.tableData.rows)));
this.dataSource.filterPredicate = this.createFilter();
}
this.dataSource.data = this.tableData.rows;
this.dataSource.filterPredicate = (data, filter) => {
console.log(data + "hier hier hier");
return true;
};
}
initFilterValues(values) {
values.forEach(key => {
this.filters[key] = "";
});
}
doFilter(filterValue: string, column: string) {
this.filters[column] = filterValue.trim().toLocaleLowerCase();
this.dataSource.filter = JSON.stringify(this.filters);
this.dataSource.filterPredicate = (data, filter) => {
console.log(data + "asdfasdfa");
return true;
};
}
createFilter() {
console.log("create asdfasdfasdfasdfasdf");
const filterFunction = function(data, filter): boolean {
console.log("Function excuted" + data);
let searchTerms = JSON.parse(filter);
return true;
};
return filterFunction;
}
}
在 HTML 中有一個輸入字段,如果我給搜索提示一些東西,doFilter 將運行,但 filterFunktion 將僅顯示所有數據的第一行數據
最好的祝福,
獅子座
[已解決] 我看到了同樣的問題。過濾器謂詞已設置但從未被調用。通過將一些 console.log 放入其中進行驗證。 我也重寫了過濾器謂詞。 [編輯] 我通過在應用過濾器之前設置謂詞來解決這個問題。這不是解決方案,但現在是很好的解決方法
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.