File tree Expand file tree Collapse file tree 2 files changed +53
-2
lines changed
packages/table-core/src/features Expand file tree Collapse file tree 2 files changed +53
-2
lines changed Original file line number Diff line number Diff line change 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+ ] ;
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments