如何在 React Table 中使用单选输入而不是复选框作为可选表?
有一个复选框但没有单选按钮的示例:https://github.com/tannerlinsley/react-table/blob/master/examples/row-selection/src/App.js https://github.com/tannerlinsley/react-table/blob/master/examples/row-selection/src/App.js
更改 InminatedCheckox 以使用无线电输入不起作用,因为反应表中的选择状态未更新:
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} />
);
});
It looks correct but does not pass the correct selection state back:
![enter image description here](https://i.stack.imgur.com/mwG90.png)
快速浏览了一下。尝试这个:
const [selectedRowId, setSelectedRowId] = useState(null);
我在这里整理了工作代码。https://codesandbox.io/s/objective-faraday-gzf7y https://codesandbox.io/s/objective-faraday-gzf7y
Notes:
- 快速变化的值可能会出现一些小问题
selectedFlatRows
。我还没有完全研究过这个问题,但我发现https://github.com/tannerlinsley/react-table/issues/1740 https://github.com/tannerlinsley/react-table/issues/1740。该问题说已修复,但我不完全确定。
- 如果您在获取行数据时遇到问题,请尝试查看以下链接是否有帮助如何获取React表行数据Onclick https://stackoverflow.com/questions/56086420/how-to-get-react-table-row-data-onclick
https://codesandbox.io/s/tannerlinsleyreact-table-row-selection-hoisted-b4dvq?from-embed https://codesandbox.io/s/tannerlinsleyreact-table-row-selection-hoisted-b4dvq?from-embed
单击反应表时选择行 https://stackoverflow.com/questions/44845372/select-row-on-click-react-table
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)