reactjs - 删除所有选定的行,即使我在其他页面中使用带有受控分页的 react-table
问题描述
使用react-table v7,即使我在其他页面中使用hook-plugin useRowSelect中的toggleAllRowsSelected ,我也很难尝试删除所有选定的行。
我在服务器端使用受控分页,正如文档所述,我设置为将 prop selectedRowIdsautoResetSelectedRows: false
存储在状态中。因此,当我更改页面时,数据会更改,但我可以保持selectedRowIds不变。当我选中或取消选中一行时,它工作正常,但我不知道如何取消选中所有这些,而不仅仅是当前页面中的行,这就是toggleAllRowsSelected正在做的事情。
我做错了什么或者是toggleAllRowsSelected回调中的错误?有没有办法操纵 react-table 的状态以手动更改selectedRowIds道具?
我以这种方式解决了它..但我认为它可能会导致性能问题...:
const handleUnselectAll = () => {
state.selectedRowIds = {};
toggleAllRowsSelected(false);
};
文档:
用户行选择:https : //react-table.tanstack.com/docs/api/useRowSelect#userowselect
解决方案
我通过使用stateReducer选项解决了这个问题。
stateReducer: (newState, action) => {
switch (action.type) {
case 'toggleAllRowsSelected':
return {
...newState,
selectedRowIds: {},
};
default:
return newState;
}
}
推荐阅读
- python - 从文本文件的数据中取平均值
- ios - 从 ChildbyAutoID Swift 中检索 Firebase 数据
- python - Python 请求的响应文本无法解析
- python - 如果密钥的日期比今天的日期早 N 天,如何删除密钥?
- android - 当我的应用主题继承自“Theme.AppCompat”时,如何自定义芯片样式?
- python - 通过字符串结尾过滤 Pandas Dataframe
- mongodb - MongoDB - 有条件地匹配两个数组
- reactjs - 做出反应。找不到编译模块失败:无法解析“react-bootsrtap”
- python - 文件 ”
",第 31 行汤 = BeautifulSoup(driver.page_source,"lxml") ^ SyntaxError: invalid syntax - sql - 在两个日期范围之间检索 SQL