javascript - 如何为反应表中的每一列添加搜索按钮以进行列过滤?
问题描述
我正在反应表中工作。我需要为每列添加搜索按钮以进行列过滤。当用户在任何列中输入关键字并单击相应的列搜索按钮时,它应该执行 API 调用并将值显示到表中。示例 UI 和代码如下所示。如果想法不清楚,请告诉我。
代码
const columns = tableColumns.map(({ key, header }) => ({
Header: (
<Tooltip arrow title={header} placement="top">
<strong className={classes.head}>{header}</strong>
</Tooltip>
),
id: key,
accessor: key,
headValue: header,
Cell: row => {
const { key: rowValue } = row;
return (
<div
style={{
textAlign: 'center'
}}
>
{rowValue && rowValue}
</div>
);
},
width: 160
}));
<DraggableTable
showPagination={false}
fixedCol={fixedCol}
filterable
// onFilteredChange={(filter, row) => columnFilter(filter, row)}
handleColumnChange={onColumnChange}
rows={tableData}
columns={columns}
style={{
height:
tableData && tableData.length === 0
? 200
: tableData && tableData.length <= 8
? tableData.length * 50 + 60
: 400,
width:
columns && columns.length === 0
? '60vw'
: columns && columns.length <= 3
? columns.length * 180
: columns && columns.length <= 6
? columns.length * 200
: columns && (columns.length > 6 && columns.length) <= 9
? columns.length * 170
: // ? 'auto'
'80vw'
// ? columns.length * 170
}}
getTrProps={(state, rowInfo) => {
return {
onClick: () => enableCellClick && onCellClick(rowInfo.original)
};
}}
resizable
/>
解决方案
推荐阅读
- angular - 使用多个组件时如何处理错误
- kotlin - 如何使用 Retrofit 和 RxJava 解析 json 数组
- javascript - Typescript:如果派生类中没有传递值,如何设置可选参数?
- python - Pyspark - 从 json 文件中获取属性名称
- android - Ionic 跨平台(ios-Android)音频分享
- java - 用户无法关闭的 MessageDialog
- sql - 分隔列(数组数组) - 高级 SQL 循环
- docker - Multistage Docker Build COPY 失败,找不到文件
- .htaccess - Apache 将参数添加到元刷新 url
- java - 如何使用 msgraph-sdk-java 将成员添加到目录角色