diff --git a/packages/react-radfish/table/index.jsx b/packages/react-radfish/table/index.jsx index 5013bb00..fe746208 100644 --- a/packages/react-radfish/table/index.jsx +++ b/packages/react-radfish/table/index.jsx @@ -159,10 +159,14 @@ const RADFishTable = ({ : sortedData; useEffect(() => { - if (paginationOptions?.currentPage) { - setPageIndex(paginationOptions.currentPage - 1); + if (totalRows === 0) { + setPageIndex(0); + } else if (paginationOptions?.currentPage && paginationOptions?.pageSize) { + const maxPage = Math.ceil(totalRows / paginationOptions.pageSize); + const newPageIndex = Math.min(Math.max(paginationOptions.currentPage - 1, 0), maxPage - 1); + setPageIndex(newPageIndex); } - }, [paginationOptions?.currentPage]); + }, [paginationOptions?.currentPage, paginationOptions?.pageSize, totalRows]); return ( <>