v.8 - I need an example for pagination-controlled with v.8 alpha #3898
-
I am implementing a react-table example for pagination-controlled (server side pagination) with v.8. I use But, when I click the pagination button (next page, or previous page, or last page), pagination state in the react-table ( I tried to solve the problem during 2 days, but couldn't figure out what is the reason of I omitted the rest of the code ! type SuccessGetRecordsData<T> = {
data: T[];
totalCount: number;
pagination:{
pageIndex: number;
pageCount: number;
pageSize: number;
};
};
const [tableData, setTableData] = useState<SuccessGetRecordsData<Authuser>>();
const [queryOptions, setQueryOptions] = useState<GetAuthusersQueryParams>({ page: 4, size: 10 });
const { isLoading, currentData } = useGetAuthusersQuery(queryOptions); // RTK Query Hook
// I supplied the weird initial pagination state, in order to figure out why pageIndex becomes 0 zero
const [pagination, setPagination] = useState<PaginationState>({
pageIndex: 1111,
pageCount: 1111, // greater than 0 zero to ensure instance.getPageCount() returns the pagination.pageCount
pageSize: 1111,
});
const [columns] = useState<typeof defaultColumns>(() => [...defaultColumns]);
const instance = useTableInstance(table, {
columns,
data: tableData ? tableData.data : [],
manualPagination: true,
state: {
pagination,
},
onPaginationChange: setPagination,
getCoreRowModel: getCoreRowModelSync(),
debugTable: true,
});
useEffect(() => {
if (currentData) {
setTableData(currentData);
// to ensure that the operation is very first fetch operation, if it is, update the react-table pagination state
if (pagination.pageSize === 1111) {
instance.setPagination(currentData.pagination);
// or setPagination(currentData.pagination) also works, I tried.
}
}
}, [currentData]);
useEffect(() => {
// I don't want the useEffect is applied for the initial render for initial weird pagination state
if (pagination.pageSize === 1111) return;
// if pagination.pageIndex is changed through clicking the buttons (prev button, or next button, or last button etc.)
if (pagination.pageIndex !== tableData?.pagination.pageIndex) {
setQueryOptions({. // update the query parameter for RTK query trigger for new fetch changing the page param
...queryOptions,
page: pagination.pageIndex + 1,
});
}
}, [pagination.pageIndex]); As you see, I use There is no example for pagination-controlled with v.8 alpha yet. I saw for the ver.7 https://codesandbox.io/s/github/tannerlinsley/react-table/tree/v7/examples/pagination-controlled I suppose we need an example for pagination-controlled with v.8 alpha. Maybe this is a bug for the react-table. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
There's a new |
Beta Was this translation helpful? Give feedback.
-
Hi! @tannerlinsley is there any example with url parameter of react router dom |
Beta Was this translation helpful? Give feedback.
There's a new
pagination-controlled
example available for v8 now.