@@ -39,6 +39,7 @@ export interface TreeDataGridProps<R, SR = unknown, K extends Key = Key>
3939 ) => Record < string , readonly NoInfer < R > [ ] > ;
4040 expandedGroupIds : ReadonlySet < unknown > ;
4141 onExpandedGroupIdsChange : ( expandedGroupIds : Set < unknown > ) => void ;
42+ groupIdGetter ?: Maybe < ( groupKey : string , parentId ?: string ) => string > ;
4243}
4344
4445type GroupByDictionary < TRow > = Record <
@@ -66,13 +67,15 @@ export function TreeDataGrid<R, SR = unknown, K extends Key = Key>({
6667 rowGrouper,
6768 expandedGroupIds,
6869 onExpandedGroupIdsChange,
70+ groupIdGetter : rawGroupIdGetter ,
6971 ...props
7072} : TreeDataGridProps < R , SR , K > ) {
7173 const defaultRenderers = useDefaultRenderers < R , SR > ( ) ;
7274 const rawRenderRow = renderers ?. renderRow ?? defaultRenderers ?. renderRow ?? defaultRenderRow ;
7375 const headerAndTopSummaryRowsCount = 1 + ( props . topSummaryRows ?. length ?? 0 ) ;
7476 const { leftKey, rightKey } = getLeftRightKey ( props . direction ) ;
7577 const toggleGroupLatest = useLatestFunc ( toggleGroup ) ;
78+ const groupIdGetter = rawGroupIdGetter ?? defaultGroupIdGetter ;
7679
7780 const { columns, groupBy } = useMemo ( ( ) => {
7881 const columns = [ ...rawColumns ] . sort ( ( { key : aKey } , { key : bKey } ) => {
@@ -144,6 +147,7 @@ export function TreeDataGrid<R, SR = unknown, K extends Key = Key>({
144147 if ( ! groupedRows ) return [ rawRows , isGroupRow ] ;
145148
146149 const flattenedRows : Array < R | GroupRow < R > > = [ ] ;
150+
147151 const expandGroup = (
148152 rows : GroupByDictionary < R > | readonly R [ ] ,
149153 parentId : string | undefined ,
@@ -154,8 +158,7 @@ export function TreeDataGrid<R, SR = unknown, K extends Key = Key>({
154158 return ;
155159 }
156160 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 ) ;
159162 const isExpanded = expandedGroupIds . has ( id ) ;
160163 const { childRows, childGroups, startRowIndex } = rows [ groupKey ] ;
161164
@@ -185,7 +188,7 @@ export function TreeDataGrid<R, SR = unknown, K extends Key = Key>({
185188 function isGroupRow ( row : R | GroupRow < R > ) : row is GroupRow < R > {
186189 return allGroupRows . has ( row ) ;
187190 }
188- } , [ expandedGroupIds , groupedRows , rawRows ] ) ;
191+ } , [ expandedGroupIds , groupedRows , rawRows , groupIdGetter ] ) ;
189192
190193 const rowHeight = useMemo ( ( ) => {
191194 if ( typeof rawRowHeight === 'function' ) {
@@ -445,6 +448,10 @@ export function TreeDataGrid<R, SR = unknown, K extends Key = Key>({
445448 ) ;
446449}
447450
451+ function defaultGroupIdGetter ( groupKey : string , parentId : string | undefined ) {
452+ return parentId !== undefined ? `${ parentId } __${ groupKey } ` : groupKey ;
453+ }
454+
448455function isReadonlyArray ( arr : unknown ) : arr is readonly unknown [ ] {
449456 return Array . isArray ( arr ) ;
450457}
0 commit comments