Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions examples/react/basic/src/data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
export type Person = {
firstName: string;
lastName: string;
age: number;
visits: number;
subRows?: Person[]; // <-- Key to nesting!
};

export const defaultData: Person[] = [
{
firstName: 'Tanner',
lastName: 'Linsley',
age: 24,
visits: 100,
subRows: [ // These are the nested rows for Tanner
{
firstName: 'Kevin',
lastName: 'Vandy',
age: 27,
visits: 200,
},
{
firstName: 'John',
lastName: 'Doe',
age: 45,
visits: 20,
subRows: [ // Deeper nesting is possible
{
firstName: 'Child',
lastName: 'Doe',
age: 5,
visits: 1,
},
],
},
],
},
{
firstName: 'Jane',
lastName: 'Doe',
age: 40,
visits: 80,
},
];
11 changes: 9 additions & 2 deletions packages/table-core/src/features/RowExpanding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,15 @@ export const RowExpanding: TableFeature = {
}

if (exists && !expanded) {
const { [row.id]: _, ...rest } = oldExpanded
return rest
const currentExpandedState = table.getState().expanded as ExpandedStateList;
const rowIds = Object.keys(currentExpandedState);
const updatedExpandedState = rowIds.reduce((acc, rowId) => {
if (!rowId.startsWith(row.id)) {
acc[rowId] = !!(currentExpandedState[rowId]);
}
return acc;
}, {} as ExpandedStateList);
return updatedExpandedState;
}

return old
Expand Down