使用钩子自动扩展行和子行反应表
问题描述:
这里我有使用钩子的反应表代码,我在打开页面时需要将所有行和子行设置为默认展开的任务时遇到了困难,我尝试了几种解决方案,但都没有工作.
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.
代码链接:https://Codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/expanding
答
正如我所说,选项 initialState.expanded
允许您扩展所需的行.
Just 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.