Skip to content

Commit 88ea0e8

Browse files
author
csl666
committed
WIP: My RowExpanding.ts fix
1 parent 02c203a commit 88ea0e8

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

examples/react/basic/src/data.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
export type Person = {
2+
firstName: string;
3+
lastName: string;
4+
age: number;
5+
visits: number;
6+
subRows?: Person[]; // <-- Key to nesting!
7+
};
8+
9+
export const defaultData: Person[] = [
10+
{
11+
firstName: 'Tanner',
12+
lastName: 'Linsley',
13+
age: 24,
14+
visits: 100,
15+
subRows: [ // These are the nested rows for Tanner
16+
{
17+
firstName: 'Kevin',
18+
lastName: 'Vandy',
19+
age: 27,
20+
visits: 200,
21+
},
22+
{
23+
firstName: 'John',
24+
lastName: 'Doe',
25+
age: 45,
26+
visits: 20,
27+
subRows: [ // Deeper nesting is possible
28+
{
29+
firstName: 'Child',
30+
lastName: 'Doe',
31+
age: 5,
32+
visits: 1,
33+
},
34+
],
35+
},
36+
],
37+
},
38+
{
39+
firstName: 'Jane',
40+
lastName: 'Doe',
41+
age: 40,
42+
visits: 80,
43+
},
44+
];

packages/table-core/src/features/RowExpanding.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,15 @@ export const RowExpanding: TableFeature = {
311311
}
312312

313313
if (exists && !expanded) {
314-
const { [row.id]: _, ...rest } = oldExpanded
315-
return rest
314+
const currentExpandedState = table.getState().expanded as ExpandedStateList;
315+
const rowIds = Object.keys(currentExpandedState);
316+
const updatedExpandedState = rowIds.reduce((acc, rowId) => {
317+
if (!rowId.startsWith(row.id)) {
318+
acc[rowId] = !!(currentExpandedState[rowId]);
319+
}
320+
return acc;
321+
}, {} as ExpandedStateList);
322+
return updatedExpandedState;
316323
}
317324

318325
return old

0 commit comments

Comments
 (0)