【发布时间】:2020-03-03 00:36:50
【问题描述】:
我们会过滤具有包含空格的值的列,例如:'Test 1'、'Test 12'、'Test 3'
我做了一个这样的自定义谓词
this.dataSource.filterPredicate = function(data: any, filterValue: string) {
return data.UserName /** replace this with the column name you want to filter */
.replace(/\s/g, "").trim()
.toLocaleLowerCase().indexOf(filterValue.replace(/\s/g, "").trim().toLocaleLowerCase()) >= 0;
};
然后是一个函数applyFilter:
applyFilter(filterValue: string) {
this.dataSource.filter = filterValue.trim().toLowerCase();
}
我仍然遇到问题: 我搜索“测试 1”,我在结果数据源测试 2、测试 3、测试 4 中看到...
我想我错过了什么
感谢您的帮助
劳伦特
【问题讨论】:
-
我没有在我的 filterPredicate 中看到 console.log。我想知道 filterPredicate 是否被触发