gpt4 book ai didi

react-table - react 表 - 重新排列 - 按列的保留位置分组

转载 作者:行者123 更新时间:2023-12-04 11:40:51 30 4
gpt4 key购买 nike

我正在使用 useGroupBy 钩子(Hook)对我的 react-table 表进行分组。但是,当分组时,默认行为是对表中的列进行分组重新排列,但我不想将它们保持在相同的位置,您知道如何使用可选的 useGroupByHook 来做到这一点吗?

这是代码和框:https://codesandbox.io/s/ecstatic-tree-bq19p?file=/src/App.js

当按 groupby 即 age 时,它​​会将 age 向左移动..

分组前:

enter image description here

enter image description here

最佳答案

您可以在表格渲染期间修复排序:

 const fixColumnOrder = (cells) => columns.map(column => cells.find(cell => cell.column.id === column.id))
 <tr {...row.getRowProps()}>
{fixColumnOrder(row.cells).map((cell) => {
return (
<td {...cell.getCellProps()}>
{cell.render('Cell')}
</td>
)
})}
</tr>
您需要对标题执行相同的技巧

关于react-table - react 表 - 重新排列 - 按列的保留位置分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61225499/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com