我有一个名为Account Verification
的列,它返回值为true
或false
。我将表中的值格式化为Yes
和No
,但是在过滤列时,我仍然必须搜索true
或false
才能过滤该列。我设置了一个自定义的过滤条件,但它不起作用。有谁有解决方案吗?
columns = [
{
headerName: 'Account Verification', field: 'accountVerified', filter: 'agTextColumnFilter',
// Cell renderer
valueFormatter: (data) => {
if (data.value === true) return 'Yes';
else return 'No';
},
// Custom filter
filterParams: {
condition: (searchTerm, cellValue) => {
if (searchTerm === 'Yes' || 'yes') {
return cellValue === true;
} else if (searchTerm === 'No' || 'no') {
return cellValue === true;
} else return cellValue === null;
}
}
}
]
"ag-grid": "^18.0.1"
发布于 2018-06-21 11:12:18
我认为实现这一点的最好方法是使用ag-grid的内置方法,比如:
这里提供了将筛选值转换为true/false的逻辑。
或者,使用javascript在过滤器的apply按钮上添加事件侦听器(如果您使用apply按钮来应用过滤器),它将调用函数来转换您的值。
目前没有示例,但我以同样的方式开发了过滤器验证(自定义)的解决方案。
发布于 2018-09-24 21:14:30
尝试以下选项之一:
发布于 2019-01-22 17:05:21
您可以在filterParams中使用TextFormatter在过滤过程中修改筛选器值:
filterParams: { textFormatter: (filterValue) => 'yourvalueformatter' }
https://www.ag-grid.com/javascript-grid-filter-text/#text-formatter
https://stackoverflow.com/questions/50966494
复制