Skip to content

Commit

Permalink
column resize event trigger after dom update
Browse files Browse the repository at this point in the history
  • Loading branch information
shaharyar-shamshi committed Feb 26, 2024
1 parent ce71551 commit 0e5732d
Showing 1 changed file with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,20 @@ export const useGridColumnResize = (

const columnVirtualizationDisabled = useColumnVirtualizationDisabled(apiRef);
const isAutosizingRef = React.useRef(false);

React.useEffect(() => {
if (colDefRef.current && !isAutosizingRef.current) {
const columnsState = gridColumnsStateSelector(apiRef.current.state);
const column: GridStateColDef = columnsState.lookup[colDefRef.current.field];
const width: number = column.width as number;
apiRef.current.publishEvent('columnWidthChange', {
element: apiRef.current.getColumnHeaderElement(colDefRef.current.field),
colDef: { ...colDefRef.current, width },
width,
});
}
}, [isAutosizingRef.current]);

const autosizeColumns = React.useCallback<GridColumnResizeApi['autosizeColumns']>(
async (userOptions) => {
const root = apiRef.current.rootElementRef?.current;
Expand Down Expand Up @@ -723,17 +737,6 @@ export const useGridColumnResize = (
}

apiRef.current.updateColumns(newColumns);

if (colDefRef.current) {
const columnsState = gridColumnsStateSelector(apiRef.current.state);
const column: GridStateColDef = columnsState.lookup[colDefRef.current.field];
const width: number = column.width as number;
apiRef.current.publishEvent('columnWidthChange', {
element: apiRef.current.getColumnHeaderElement(colDefRef.current.field),
colDef: { ...colDefRef.current, width },
width,
});
}
} finally {
apiRef.current.unstable_setColumnVirtualization(true);
isAutosizingRef.current = false;
Expand Down

0 comments on commit 0e5732d

Please sign in to comment.