Skip to content

Commit b10446b

Browse files
committed
fix: useExpanded uses flat array for state
useExpanded now uses a flat array of row path keys for tracking expanded state instead of nested objects. This is both easier to use as a developer, but also enables expanding all rows or even leaving nested rows in an expanded state, despite their parent rows' expanded state. BREAKING CHANGE: See description
1 parent 51165d9 commit b10446b

File tree

6 files changed

+676
-93
lines changed

6 files changed

+676
-93
lines changed

docs/api.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -940,12 +940,12 @@ function App() {
940940

941941
The following options are supported via the main options object passed to `useTable(options)`
942942

943-
- `state[0].expanded: Object<[pathIndex]: Boolean | ExpandedStateObject>`
943+
- `state[0].expanded: Array<pathKey: String>`
944944
- Optional
945945
- Must be **memoized**
946-
- An nested object of expanded paths.
947-
- A `pathIndex` can be set as the key and its value set to `true` to expand that row's subRows into view. For example, if `{ '3': true }` was passed as the `expanded` state, the **4th row in the original data array** would be expanded.
948-
- For nested expansion, you may **use another object** instead of a Boolean to expand sub rows. For example, if `{ '3': { '5' : true }}` was passed as the `expanded` state, then the **6th subRow of the 4th row and the 4th row of the original data array** would be expanded.
946+
- An array of expanded path keys.
947+
- If a row's path key (`row.path.join('.')`) is present in this array, that row will have an expanded state. For example, if `['3']` was passed as the `expanded` state, the **4th row in the original data array** would be expanded.
948+
- For nested expansion, you may **join the row path with a `.`** to expand sub rows. For example, if `['3', '3.5']` was passed as the `expanded` state, then the **6th subRow of the 4th row and also the 4th row of the original data array** would be expanded.
949949
- This information is stored in state since the table is allowed to manipulate the filter through user interaction.
950950
- `getSubRows: Function(row, relativeIndex) => Rows[]`
951951
- Optional

examples/expanding/src/App.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ function Table({ columns: userColumns, data }) {
5050

5151
return (
5252
<>
53-
<pre>
54-
<code>{JSON.stringify({ expanded }, null, 2)}</code>
55-
</pre>
5653
<table {...getTableProps()}>
5754
<thead>
5855
{headerGroups.map(headerGroup => (
@@ -80,6 +77,9 @@ function Table({ columns: userColumns, data }) {
8077
</table>
8178
<br />
8279
<div>Showing the first 20 results of {rows.length} rows</div>
80+
<pre>
81+
<code>{JSON.stringify({ expanded }, null, 2)}</code>
82+
</pre>
8383
</>
8484
)
8585
}

0 commit comments

Comments
 (0)