react-table setFilter 具有自定义过滤功能?

问题描述 投票:0回答:1

我正在尝试使用

react-table
在列上设置过滤器。我想要更改复选框以过滤一列的多个可能值。

假设我有一张这样的桌子。当选中该复选框时 - 我希望显示所有实例。未选中时,我想要除实例之外的所有内容。

const columns = useMemo( () => [
  {
   Header: 'col1',
  accessor: 'col1'
  },
 {
   Header: 'col2',
  accessor: 'col2'
  } 
 {
   Header: 'col3',
  accessor: 'col3'
  } 
], [] )

const {
...
setFilter,
filters,
} = useTable(
  {columns, data},
  useFilters
  ....
)



const onFilterChange= (e, value) => {
   if(e.target.checked){
     setFilter('col3', 'instance') //works!
   }
   else{
     setFilter('col3', cell => cell.value !== 'instance' ) //does not work - how do I do this?
   }
   

}


return (
<input
  type="checkbox"
  onChange={ e => onFilterChange(e, 'instance')}
  />

)

我可以将自定义函数传递给

setFilter
吗?不知道如何使用
react-table

做到这一点
reactjs react-hooks react-table
1个回答
0
投票

据我所知,参数是旧的过滤器值,而不是单元格

© www.soinside.com 2019 - 2024. All rights reserved.