我想要一个单选选项列组件,因此使用了 column-props 的 filterComponent
属性来呈现一个自定义的单选 Material-UI 组件。更改选项时,选择的值会更新。但我还需要过滤掉行数据。如何实现?
使用列道具支持的 customFilterAndSearch
道具,由于使用 filterComponent
覆盖现有组件,因此不会被调用。
尝试调用选择选项的 customFilterAndSearch
onChange,为此,customFilterAndSearch
需要 2 个参数 1. 选项/过滤器值,2. 行数据。我可以获取第一个参数值,但是有没有办法获取行数据?
{
title: "Birth Place",
field: "birthCity",
lookup: birthCity,
customFilterAndSearch: (data, rowData) => {
console.log({ data, rowData });
return true;
},
filterComponent: (props) => {
return (
<Select
value={city}
onChange={(e) => {
setCity(e.target.value);
props.columnDef.customFilterAndSearch(e.target.value, {}); // don't know how to idenitfy row data and send as a parameter
}}
>
{Object.keys(birthCity).map((key) => {
return <MenuItem value={key}> {key} </MenuItem>;
})}
</Select>
);
}
}
链接到 codesandbox