@@ -39,6 +39,7 @@ export interface TreeDataGridProps<R, SR = unknown, K extends Key = Key>
39
39
) => Record < string , readonly NoInfer < R > [ ] > ;
40
40
expandedGroupIds : ReadonlySet < unknown > ;
41
41
onExpandedGroupIdsChange : ( expandedGroupIds : Set < unknown > ) => void ;
42
+ groupIdGetter ?: Maybe < ( groupKey : string , parentId ?: string ) => string > ;
42
43
}
43
44
44
45
type GroupByDictionary < TRow > = Record <
@@ -66,13 +67,15 @@ export function TreeDataGrid<R, SR = unknown, K extends Key = Key>({
66
67
rowGrouper,
67
68
expandedGroupIds,
68
69
onExpandedGroupIdsChange,
70
+ groupIdGetter : rawGroupIdGetter ,
69
71
...props
70
72
} : TreeDataGridProps < R , SR , K > ) {
71
73
const defaultRenderers = useDefaultRenderers < R , SR > ( ) ;
72
74
const rawRenderRow = renderers ?. renderRow ?? defaultRenderers ?. renderRow ?? defaultRenderRow ;
73
75
const headerAndTopSummaryRowsCount = 1 + ( props . topSummaryRows ?. length ?? 0 ) ;
74
76
const { leftKey, rightKey } = getLeftRightKey ( props . direction ) ;
75
77
const toggleGroupLatest = useLatestFunc ( toggleGroup ) ;
78
+ const groupIdGetter = rawGroupIdGetter ?? defaultGroupIdGetter ;
76
79
77
80
const { columns, groupBy } = useMemo ( ( ) => {
78
81
const columns = [ ...rawColumns ] . sort ( ( { key : aKey } , { key : bKey } ) => {
@@ -144,6 +147,7 @@ export function TreeDataGrid<R, SR = unknown, K extends Key = Key>({
144
147
if ( ! groupedRows ) return [ rawRows , isGroupRow ] ;
145
148
146
149
const flattenedRows : Array < R | GroupRow < R > > = [ ] ;
150
+
147
151
const expandGroup = (
148
152
rows : GroupByDictionary < R > | readonly R [ ] ,
149
153
parentId : string | undefined ,
@@ -154,8 +158,7 @@ export function TreeDataGrid<R, SR = unknown, K extends Key = Key>({
154
158
return ;
155
159
}
156
160
Object . keys ( rows ) . forEach ( ( groupKey , posInSet , keys ) => {
157
- // TODO: should users have control over the generated key?
158
- const id = parentId !== undefined ? `${ parentId } __${ groupKey } ` : groupKey ;
161
+ const id = groupIdGetter ( groupKey , parentId ) ;
159
162
const isExpanded = expandedGroupIds . has ( id ) ;
160
163
const { childRows, childGroups, startRowIndex } = rows [ groupKey ] ;
161
164
@@ -185,7 +188,7 @@ export function TreeDataGrid<R, SR = unknown, K extends Key = Key>({
185
188
function isGroupRow ( row : R | GroupRow < R > ) : row is GroupRow < R > {
186
189
return allGroupRows . has ( row ) ;
187
190
}
188
- } , [ expandedGroupIds , groupedRows , rawRows ] ) ;
191
+ } , [ expandedGroupIds , groupedRows , rawRows , groupIdGetter ] ) ;
189
192
190
193
const rowHeight = useMemo ( ( ) => {
191
194
if ( typeof rawRowHeight === 'function' ) {
@@ -445,6 +448,10 @@ export function TreeDataGrid<R, SR = unknown, K extends Key = Key>({
445
448
) ;
446
449
}
447
450
451
+ function defaultGroupIdGetter ( groupKey : string , parentId : string | undefined ) {
452
+ return parentId !== undefined ? `${ parentId } __${ groupKey } ` : groupKey ;
453
+ }
454
+
448
455
function isReadonlyArray ( arr : unknown ) : arr is readonly unknown [ ] {
449
456
return Array . isArray ( arr ) ;
450
457
}
0 commit comments