How to set default page size? #2029
-
Hi, How can I initially set default page size to be 15? |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 14 replies
-
Set the “pageSize” of the initial state. https://github.com/tannerlinsley/react-table/blob/master/docs/api/usePagination.md#table-options |
Beta Was this translation helpful? Give feedback.
-
can you give me an example code for it? |
Beta Was this translation helpful? Give feedback.
-
Here the edited pagination example with page size of 15: |
Beta Was this translation helpful? Give feedback.
-
2023 solution:
|
Beta Was this translation helpful? Give feedback.
-
for v8 |
Beta Was this translation helpful? Give feedback.
-
I had the same problem, but importing and using PaginationState did it. Using v8.
declare columns etc...
then use it within your table...
That will make your buttons keep working, hope it helps. |
Beta Was this translation helpful? Give feedback.
-
From the official pagination guide: Pagination State The pagination state is an object that contains the following properties: pageIndex: The current page index (zero-based). import { useReactTable, getCoreRowModel, getPaginationRowModel } from '@tanstack/react-table';
//...
const [pagination, setPagination] = useState({
pageIndex: 0, //initial page index
pageSize: 10, //default page size
});
const table = useReactTable({
columns,
data,
getCoreRowModel: getCoreRowModel(),
getPaginationRowModel: getPaginationRowModel(),
onPaginationChange: setPagination, //update the pagination state when internal APIs mutate the pagination state
state: {
//...
pagination,
},
}); Alternatively, if you have no need for managing the pagination state in your own scope, but you need to set different initial values for the pageIndex and pageSize, you can use the initialState option. const table = useReactTable({
columns,
data,
getCoreRowModel: getCoreRowModel(),
getPaginationRowModel: getPaginationRowModel(),
initialState: {
pagination: {
pageIndex: 2, //custom initial page index
pageSize: 25, //custom default page size
},
},
});
|
Beta Was this translation helpful? Give feedback.
-
@KevinVandy Thanks |
Beta Was this translation helpful? Give feedback.
From the official pagination guide:
Pagination State
Whether or not you are using client-side or manual server-side pagination, you can use the built-in pagination state state and APIs.
The pagination state is an object that contains the following properties:
pageIndex: The current page index (zero-based).
pageSize: The current page size.
You can manage the pagination state just like any other state in the table instance.