javascript - React Table - useRowSelect 的单选输入
问题描述
如何在 React Table 中使用单选输入而不是复选框来选择表?
有一个复选框但不是单选按钮的示例:https ://github.com/tannerlinsley/react-table/blob/master/examples/row-selection/src/App.js
将 IndeterminateCheckox 更改为使用单选输入不起作用,因为 React Table 中的选择状态未更新:
const IndeterminateCheckbox = React.forwardRef(({ indeterminate, ...rest }, ref) => {
const defaultRef = React.useRef();
const resolvedRef = ref || defaultRef;
useEffect(() => {
resolvedRef.current.indeterminate = indeterminate;
}, [resolvedRef, indeterminate]);
return <input name="select-radio" type="radio" ref={resolvedRef} {...rest} />
);
});
解决方案
快速浏览了一下。尝试这个:
- 有 rowId 的状态
const [selectedRowId, setSelectedRowId] = useState(null);
- 传递
autoResetSelectedRows: false,
给useTable
函数 手动为收音机编写点击处理程序
onClick={() => setSelectedRowId(row.id)}
我在这里整理了工作代码。 https://codesandbox.io/s/objective-faraday-gzf7y
笔记:
- 快速变化的值可能存在一些小问题
selectedFlatRows
。我还没有完全研究过这个问题,但我发现了https://github.com/tannerlinsley/react-table/issues/1740。问题说已解决,但我不完全确定。 - 如果您在获取行数据时遇到问题,请尝试查看以下链接是否有帮助 如何获取 React Table Row Data Onclick https://codesandbox.io/s/tannerlinsleyreact-table-row-selection-hoisted-b4dvq?from -在点击反应表上嵌入 选择行
推荐阅读
- dialogflow-es - Dialogflow 不会将参数评估为其参考值
- kubernetes - 使用 url 登录 K8S Dashboard
- python - 为什么多处理在 python 中不起作用
- android - 如何将波纹动画添加到具有自定义背景的小部件?
- kendo-combobox - 无法将远程数据加载到 kendoComboBox
- yaml - 如何为各个功能网关事件分配 APIkey?
- java - Service中的异步任务,什么时候调用stopSelf方法?
- amazon-web-services - 用户无权执行:execute-api:Invoke on resource 尝试从 Lambda 调用 APIG
- apache - .htpasswd 不保护 .txt 文件
- laravel - 如何在 Laravel 上使用 Carbon 验证给定时间大于当前时间?