@@ -50,6 +50,7 @@ import type {
5050 CellSelectArgs ,
5151 Column ,
5252 ColumnOrColumnGroup ,
53+ ColumnWidths ,
5354 Direction ,
5455 FillEvent ,
5556 Maybe ,
@@ -159,6 +160,8 @@ export interface DataGridProps<R, SR = unknown, K extends Key = Key> extends Sha
159160 * @default 35
160161 */
161162 summaryRowHeight ?: Maybe < number > ;
163+ columnWidths ?: Maybe < ColumnWidths > ;
164+ onColumnWidthsChange ?: Maybe < ( columnWidths : ColumnWidths ) => void > ;
162165
163166 /**
164167 * Feature props
@@ -235,9 +238,6 @@ export interface DataGridProps<R, SR = unknown, K extends Key = Key> extends Sha
235238 direction ?: Maybe < Direction > ;
236239 'data-testid' ?: Maybe < string > ;
237240 'data-cy' ?: Maybe < string > ;
238-
239- columnWidths ?: Maybe < ReadonlyMap < string , number > > ;
240- onColumnWidthsChange ?: Maybe < ( widths : ReadonlyMap < string , number > ) => void > ;
241241}
242242
243243/**
@@ -261,6 +261,8 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr
261261 rowHeight : rawRowHeight ,
262262 headerRowHeight : rawHeaderRowHeight ,
263263 summaryRowHeight : rawSummaryRowHeight ,
264+ columnWidths,
265+ onColumnWidthsChange,
264266 // Feature props
265267 selectedRows,
266268 isRowSelectionDisabled,
@@ -297,10 +299,7 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr
297299 'aria-describedby' : ariaDescribedBy ,
298300 'aria-rowcount' : rawAriaRowCount ,
299301 'data-testid' : testId ,
300- 'data-cy' : dataCy ,
301-
302- columnWidths,
303- onColumnWidthsChange
302+ 'data-cy' : dataCy
304303 } = props ;
305304
306305 /**
@@ -326,19 +325,29 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr
326325 */
327326 const [ scrollTop , setScrollTop ] = useState ( 0 ) ;
328327 const [ scrollLeft , setScrollLeft ] = useState ( 0 ) ;
329- const [ resizedColumnWidths , setResizedColumnWidths ] = useState (
330- ( ) : ReadonlyMap < string , number > => new Map ( )
328+ const [ resizedColumnWidthsInternal , setResizedColumnWidthsInternal ] = useState (
329+ ( ) : ReadonlyMap < string , number > => columnWidths ?. resized ?? new Map ( )
331330 ) ;
332331 const [ measuredColumnWidthsInternal , setMeasuredColumnWidthsInternal ] = useState (
333- ( ) : ReadonlyMap < string , number > => columnWidths ?? new Map ( )
332+ ( ) : ReadonlyMap < string , number > => columnWidths ?. measured ?? new Map ( )
334333 ) ;
335334 const isColumnWidthsControlled = columnWidths != null && onColumnWidthsChange != null ;
336335 const measuredColumnWidths = isColumnWidthsControlled
337- ? columnWidths
336+ ? columnWidths . measured
338337 : measuredColumnWidthsInternal ;
339338 const setMeasuredColumnWidths = isColumnWidthsControlled
340- ? onColumnWidthsChange
339+ ? ( measuredColumnWidths : ReadonlyMap < string , number > ) => {
340+ onColumnWidthsChange ( { ...columnWidths , measured : measuredColumnWidths } ) ;
341+ }
341342 : setMeasuredColumnWidthsInternal ;
343+ const resizedColumnWidths = isColumnWidthsControlled
344+ ? columnWidths . resized
345+ : resizedColumnWidthsInternal ;
346+ const setResizedColumnWidths = isColumnWidthsControlled
347+ ? ( resizedColumnWidths : ReadonlyMap < string , number > ) => {
348+ onColumnWidthsChange ( { ...columnWidths , resized : resizedColumnWidths } ) ;
349+ }
350+ : setResizedColumnWidthsInternal ;
342351
343352 const [ isDragging , setDragging ] = useState ( false ) ;
344353 const [ draggedOverRowIdx , setOverRowIdx ] = useState < number | undefined > ( undefined ) ;
0 commit comments