Handle list auto size when vertical scroll appears

This commit is contained in:
jeffvli 2023-05-11 01:58:04 -07:00
parent cf489d3934
commit 4eb90d20a2

View file

@ -10,6 +10,7 @@ import type {
NewColumnsLoadedEvent, NewColumnsLoadedEvent,
GridReadyEvent, GridReadyEvent,
GridSizeChangedEvent, GridSizeChangedEvent,
ModelUpdatedEvent,
} from '@ag-grid-community/core'; } from '@ag-grid-community/core';
import type { AgGridReactProps } from '@ag-grid-community/react'; import type { AgGridReactProps } from '@ag-grid-community/react';
import { AgGridReact } from '@ag-grid-community/react'; import { AgGridReact } from '@ag-grid-community/react';
@ -418,6 +419,14 @@ export const VirtualTable = forwardRef(
[autoFitColumns, onGridSizeChanged], [autoFitColumns, onGridSizeChanged],
); );
const handleModelUpdated = useCallback(
(e: ModelUpdatedEvent) => {
if (!e?.api) return;
if (autoFitColumns) e.api?.sizeColumnsToFit?.();
},
[autoFitColumns],
);
return ( return (
<TableWrapper <TableWrapper
ref={deselectRef} ref={deselectRef}
@ -447,6 +456,7 @@ export const VirtualTable = forwardRef(
onColumnMoved={handleColumnMoved} onColumnMoved={handleColumnMoved}
onGridReady={handleGridReady} onGridReady={handleGridReady}
onGridSizeChanged={handleGridSizeChanged} onGridSizeChanged={handleGridSizeChanged}
onModelUpdated={handleModelUpdated}
onNewColumnsLoaded={handleNewColumnsLoaded} onNewColumnsLoaded={handleNewColumnsLoaded}
/> />
</TableWrapper> </TableWrapper>