admin管理员组文章数量:1327939
Here I have code of react table using hooks, and i have struggled on task where I need to set all rows and subrows expanded by default when i open the page, I have tried several solutions, but all of them didn't work.
Link to the code :
Here I have code of react table using hooks, and i have struggled on task where I need to set all rows and subrows expanded by default when i open the page, I have tried several solutions, but all of them didn't work.
Link to the code : https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/expanding
Share Improve this question edited Feb 6, 2020 at 5:31 asked Feb 5, 2020 at 11:10 user12844904user12844904 1-
It looks like that
react-table
has an optioninitialState.expanded
to pass touseTable
. github./tannerlinsley/react-table/blob/… – robinvrd Commented Feb 5, 2020 at 11:16
2 Answers
Reset to default 6Just as I said, the option initialState.expanded
allows you to expand the rows you want.
useTable(
{
columns: userColumns,
data,
initialState: {
expanded: { "0": true, "2": true }
}
},
useExpanded // Use the useExpanded plugin hook
)
This will expand the first and the third row.
I'm not sure this is still relevant 4+ years later, but in the latest MRT V2 you can simply say:
initialState: {
expanded: true
},
and just like that all your rows / subrows will start expanded. No need for clumsy loops over your data and such imperative hacks.
In the meantime, the codesandbox changed to https://codesandbox.io/p/devbox/github/TanStack/table/tree/main/examples/react/expanding
Enjoy!
本文标签: javascriptAuto expandable rows and subrows react table using hooksStack Overflow
版权声明:本文标题:javascript - Auto expandable rows and subrows react table using hooks - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742253566a2441207.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论