P粉1871608832023-09-03 09:31:11
You need to store the page index in a state variable and pass the setState method to the tanstack table to set the current page index. You can try the following code:
const [state, setState] = useState(table.initialState); const [{ pageIndex, pageSize }, setPagination] = useState<PaginationState>({ pageIndex: 0, pageSize: 10 }); const pagination = useMemo( () => ({ pageIndex, pageSize }), [pageIndex, pageSize] ); // override the state managers for the table table.setOptions(prev => ({ ...prev, onStateChange: setState, state: { ...state, pagination, }, onPaginationChange: setPagination, pageCount: Math.ceil(numOfRows / pageSize) }));