diff --git a/src/components/InfiniteTable/InfiniteTable.tsx b/src/components/InfiniteTable/InfiniteTable.tsx index e4d6250..9e9cb16 100644 --- a/src/components/InfiniteTable/InfiniteTable.tsx +++ b/src/components/InfiniteTable/InfiniteTable.tsx @@ -90,6 +90,7 @@ const InfiniteTableComp = forwardRef( } = props; const gridRef = useRef(null); + const firstTimeDataLoaded = useRef(true); const firstTimeOnBodyScroll = useRef(true); const allRowSelectedModeRef = useRef(false); const containerRef = useRef(null); @@ -265,6 +266,13 @@ const InfiniteTableComp = forwardRef( totalRows, ]); + const scrollToSavedPosition = useCallback(() => { + const firstVisibleRowIndex = onGetFirstVisibleRowIndex?.(); + if (firstVisibleRowIndex && gridRef.current?.api) { + gridRef.current.api.ensureIndexVisible(firstVisibleRowIndex, "top"); + } + }, [onGetFirstVisibleRowIndex]); + const getRows = useCallback( async (params: IGetRowsParams) => { gridRef.current?.api.showLoadingOverlay(); @@ -321,6 +329,10 @@ const InfiniteTableComp = forwardRef( } } gridRef.current?.api.hideOverlay(); + if (firstTimeDataLoaded.current) { + firstTimeDataLoaded.current = false; + scrollToSavedPosition(); + } }, [ getSortedFields, @@ -328,6 +340,7 @@ const InfiniteTableComp = forwardRef( onGetSelectedRowKeys, onRequestData, onRowStatus, + scrollToSavedPosition, selectedRowKeysPendingToRender, setSelectedRowKeysPendingToRender, ], @@ -350,16 +363,6 @@ const InfiniteTableComp = forwardRef( [onRowDoubleClick], ); - const onFirstDataRendered = useCallback( - (params: FirstDataRenderedEvent) => { - const firstVisibleRowIndex = onGetFirstVisibleRowIndex?.(); - if (firstVisibleRowIndex) { - params.api.ensureIndexVisible(firstVisibleRowIndex, "top"); - } - }, - [onGetFirstVisibleRowIndex], - ); - const onBodyScroll = useCallback( (params: BodyScrollEvent) => { if (!firstTimeOnBodyScroll.current) { @@ -407,7 +410,6 @@ const InfiniteTableComp = forwardRef( infiniteInitialRowCount={50} maxBlocksInCache={10} onGridReady={onGridReady} - onFirstDataRendered={onFirstDataRendered} onBodyScroll={onBodyScroll} blockLoadDebounceMillis={DEBOUNCE_TIME} suppressDragLeaveHidesColumns={true}