Rumah > Soal Jawab > teks badan
P粉1871608832023-09-03 09:31:11
Anda perlu menyimpan indeks halaman dalam pembolehubah keadaan dan hantar kaedah setState ke jadual tanstack untuk menetapkan indeks halaman semasa. Anda boleh mencuba kod berikut:
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) }));