mirror of
https://github.com/gosticks/react-table.git
synced 2025-10-16 11:55:36 +00:00
4.9 KiB
4.9 KiB
usePagination
- Plugin Hook
- Optional
usePagination is the hook that implements row pagination. It can be used for both client-side pagination or server-side pagination. For more information on pagination, see Pagination
Note
Some server-side pagination implementations do not use page index and instead use token based pagination! If that's the case, please use the
useTokenPaginationplugin instead.
Table Options
The following options are supported via the main options object passed to useTable(options)
state.pageSize: Int- Required
- Defaults to
10 - Determines the amount of rows on any given page
initialState.pageSize- Identical to the
state.pageSizeoption above
- Identical to the
state.pageIndex: Int- Required
- Defaults to
0 - The index of the page that should be displayed via the
pageinstance value
initialState.pageIndex- Identical to the
state.pageIndexoption above
- Identical to the
pageCount: Int- Required if
manualPaginationis set totrue - If
manualPaginationistrue, then this value used to determine the amount of pages available. This amount is then used to materialize thepageOptionsand also compute thecanNextPagevalues on the table instance.
- Required if
manualPagination: Bool- Enables pagination functionality, but does not automatically perform row pagination.
- Turn this on if you wish to implement your own pagination outside of the table (eg. server-side pagination or any other manual pagination technique)
autoResetPage: Boolean- Defaults to
true - When
true, theexpandedstate will automatically reset ifmanualPaginationisfalseand any of the following conditions are met:datais changedmanualSortByisfalseandstate.sortByis changedmanualFiltersisfalseandstate.filtersis changedmanualGroupByisfalseandstate.groupByis changed
- To disable, set to
false - For more information see the FAQ "How do I stop my table state from automatically resetting when my data changes?"
- Defaults to
paginateExpandedRows: Bool- Optional
- Only applies when using the
useExpandedplugin hook simultaneously - Defaults to
true - If set to
true, expanded rows are paginated along with normal rows. This results in stable page sizes across every page. - If set to
false, expanded rows will be spliced in after pagination. This means that the total number of rows in a page can potentially be larger than the page size, depending on how many subrows are expanded.
Instance Properties
The following values are provided to the table instance:
page: Array<row>- An array of rows for the current page, determined by the current
pageIndexvalue.
- An array of rows for the current page, determined by the current
pageCount: Int- If
manualPaginationis set tofalse, this is the total amount of pages available in the table based on the currentpageSizevalue - if
manualPaginationis set totrue, this is merely the samepageCountoption that was passed in the table options.
- If
pageOptions: Array<Int>- An array of zero-based index integers corresponding to available pages in the table.
- This can be useful for generating things like select interfaces for the user to select a page from a list, instead of manually paginating to the desired page.
canPreviousPage: Bool- If there are pages and the current
pageIndexis greater than0, this will betrue
- If there are pages and the current
canNextPage:- If there are pages and the current
pageIndexis less thanpageCount, this will betrue
- If there are pages and the current
gotoPage: Function(pageIndex)- This function, when called with a valid
pageIndex, will setpageIndexto that value. - If the aginateassed index is outside of the valid
pageIndexrange, then this function will do nothing.
- This function, when called with a valid
previousPage: Function- This function decreases
state.pageIndexby one. - If there are no pages or
canPreviousPageis false, this function will do nothing.
- This function decreases
nextPage: Function- This function increases
state.pageIndexby one. - If there are no pages or
canNextPageis false, this function will do nothing.
- This function increases
setPageSize: Function(pageSize)- This function sets
state.pageSizeto the new value. - As a result of a pageSize change, a new
state.pageIndexis also calculated. It is calculated viaMath.floor(currentTopRowIndex / newPageSize)
- This function sets
pageIndex: Int- This is the resolved
state.pageIndexvalue.
- This is the resolved
pageSize: Int- This is the resolved
state.pageSizevalue.
- This is the resolved
Example
- Basic Pagination
- Controlled Pagination