- 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
useTokenPagination
plugin instead.
The following options are supported via the main options object passed to useTable(options)
initialState.pageSize: Int
- Required
- Defaults to
10
- Determines the amount of rows on any given page
initialState.pageIndex: Int
- Required
- Defaults to
0
- The index of the page that should be displayed via the
page
instance value
pageCount: Int
- Required if
manualPagination
is set totrue
- If
manualPagination
istrue
, then this value used to determine the amount of pages available. This amount is then used to materialize thepageOptions
and also compute thecanNextPage
values on the table instance. - Set to
-1
if you don't know or don't want to present the number of pages available.canNextPage
will returnfalse
if page data length is less than pageSize, otherwisetrue
.
- 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
, thepageIndex
state will automatically reset ifmanualPagination
isfalse
and any of the following conditions are met:data
is changedmanualSortBy
isfalse
andstate.sortBy
is changedmanualGlobalFilter
isfalse
andstate.globalFilter
is changedmanualFilters
isfalse
andstate.filters
is changedmanualGroupBy
isfalse
andstate.groupBy
is 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
useExpanded
plugin 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.
The following values are provided to the table instance
:
state.pageIndex: Int
- This is the current
pageIndex
value, located on the state.
- This is the current
state.pageSize: Int
- This is the current
pageSize
value, located on the state.
- This is the current
page: Array<row>
- An array of rows for the current page, determined by the current
pageIndex
value.
- An array of rows for the current page, determined by the current
pageCount: Int
- If
manualPagination
is set tofalse
, this is the total amount of pages available in the table based on the currentpageSize
value - if
manualPagination
is set totrue
, this is merely the samepageCount
option 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
pageIndex
is greater than0
, this will betrue
- If there are pages and the current
canNextPage:
- If there are pages and the current
pageIndex
is less thanpageCount
, this will betrue
- If there are pages and the current
gotoPage: Function(pageIndex)
- This function, when called with a valid
pageIndex
, will setpageIndex
to that value. - If the aginateassed index is outside of the valid
pageIndex
range, then this function will do nothing.
- This function, when called with a valid
previousPage: Function
- This function decreases
state.pageIndex
by one. - If there are no pages or
canPreviousPage
is false, this function will do nothing.
- This function decreases
nextPage: Function
- This function increases
state.pageIndex
by one. - If there are no pages or
canNextPage
is false, this function will do nothing.
- This function increases
setPageSize: Function(pageSize)
- This function sets
state.pageSize
to the new value. - As a result of a pageSize change, a new
state.pageIndex
is also calculated. It is calculated viaMath.floor(currentTopRowIndex / newPageSize)
- This function sets
- Basic Pagination
- Controlled Pagination