Heim > Fragen und Antworten > Hauptteil
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) }));