Table: Update page index on data update (#81574)

* fix(table): page index reset on data update
This commit is contained in:
Ihor Yeromin 2024-02-13 14:21:36 +02:00 committed by GitHub
parent 6c42bd31c6
commit 1abe4a02b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -237,6 +237,17 @@ export const Table = memo((props: Props) => {
setPageSize(pageSize);
}, [pageSize, setPageSize]);
useEffect(() => {
// Reset page index when data changes
// This is needed because react-table does not do this automatically
// autoResetPage is set to false because setting it to true causes the issue described in
// https://github.com/grafana/grafana/pull/67477
if (data.length / pageSize < state.pageIndex) {
gotoPage(0);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [data]);
useResetVariableListSizeCache(extendedState, listRef, data, hasUniqueId);
useFixScrollbarContainer(variableSizeListScrollbarRef, tableDivRef);