【发布时间】:2021-02-07 14:50:40
【问题描述】:
我正在尝试在 antD 中使用自定义过滤器,使用 react with typescript。 它没有渲染任何东西,我不知道我做错了什么。
这是我返回列道具的函数:
const getColumnSearchProps = (dataIndex: string) => ({
filterDropDown:
({
setSelectedKeys,
selectedKeys,
confirm,
clearFilters
}: any) => (
<div style={{ padding: 8 }}>
<Input
ref={ searchInput }
placeholder={`Search ${dataIndex}`}
onChange={e => setSelectedKeys(e.target.value ? [e.target.value] : [])}
value={selectedKeys[0]}
/>
<Space>
<Button
type="primary"
onClick={() => handleSearch(selectedKeys, confirm)}
icon={<SearchOutlined />}
size="small"
style={{ width: 90 }}
>
Search
</Button>
<Button size="small" style={{ width: 90 }}>
Reset
</Button>
<Button
type="link"
size="small"
>
Filter
</Button>
</Space>
</div>
),
filterIcon: (filtered: boolean) => (
<SearchOutlined style={{ color: filtered ? "#1890ff" : undefined }} />
),
onFilterDropdownVisibleChange: (visible: boolean) => {
if (visible) {
setTimeout(() => searchInput.current?.select(), 100);
}
}
})
这就是我传播这些道具的方式:
const columns: any = [
{
title: 'Name',
dataIndex: 'candidate',
key: "candidate",
width: '16.66%',
render: (name: string) => cellRender(name),
...getColumnSearchProps("name")
}
....
我想像这样渲染过滤器:
【问题讨论】:
标签: reactjs typescript antd