@@ -37,10 +37,7 @@ export const useGridState = (
3737 ...defaultVisibility ,
3838 ...( savedState . columnVisibility || { } )
3939 } ,
40- columnSizing : {
41- ...defaultSizing ,
42- ...( savedState . columnSizing || { } )
43- }
40+ columnSizing : savedState . columnSizing || { }
4441 } ;
4542 } ) ;
4643
@@ -71,24 +68,26 @@ export const useGridState = (
7168 } , [ saveToStorage ] ) ;
7269
7370 const resetColumnSizes = useCallback ( ( ) => {
74- const defaultSizing = columns ?. reduce ( ( acc , col ) => ( {
75- ...acc ,
76- [ col . field ] : col . width || 150
77- } ) , { } ) ;
78-
79- setGridState ( prev => {
80- const newState = { ...prev , columnSizing : defaultSizing } ;
71+ // reset to empty, restores original flex/width definition
72+ setGridState ( prev => {
73+ const newState = { ...prev , columnSizing : { } } ;
8174 saveToStorage ( newState ) ;
8275 return newState ;
8376 } ) ;
84- } , [ columns , saveToStorage ] ) ;
77+ } , [ saveToStorage ] ) ;
8578
8679 // Memoize columns with applied widths so objects are stable between renders
87- const columnsWithSizing = useMemo ( ( ) => columns ?. map ( col => ( {
88- ...col ,
89- width : gridState . columnSizing [ col . field ] || col . width || 150
90- } ) ) , [ columns , gridState . columnSizing ] ) ;
80+ const columnsWithSizing = useMemo ( ( ) => columns ?. map ( col => {
81+ const userWidth = gridState . columnSizing [ col . field ] ;
9182
83+ if ( userWidth !== undefined ) {
84+ const { flex, minWidth, ...colWithoutFlex } = col as any ;
85+ return { ...colWithoutFlex , width : userWidth } ;
86+ }
87+ return col ;
88+ } ) ,
89+ [ columns , gridState . columnSizing ]
90+ ) ;
9291 return {
9392 columnVisibility : gridState . columnVisibility ,
9493 columnSizing : gridState . columnSizing ,
0 commit comments