Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto expandable rows and subrows react table using hooks

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


1 Answers

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.

like image 175
robinvrd Avatar answered Jan 20 '26 11:01

robinvrd