P粉1871608832023-09-03 09:31:11
您需要將頁面索引儲存在狀態變數中,並將 setState 方法傳遞給 tanstack 表以設定目前頁面索引。您可以嘗試以下程式碼:
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) }));