usePagination
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
10
initialState.pageIndex: Int
0
page
instance valuepageCount: Int
manualPagination
is set to true
manualPagination
is true
, then this value used to determine the amount of pages available. This amount is then used to materialize the pageOptions
and also compute the canNextPage
values on the table instance.-1
if you don't know or don't want to present the number of pages available. canNextPage
will return false
if page data length is less than pageSize, otherwise true
.manualPagination: Bool
autoResetPage: Boolean
true
true
, the pageIndex
state will automatically reset if manualPagination
is false
and any of the following conditions are met:data
is changedmanualSortBy
is false
and state.sortBy
is changedmanualGlobalFilter
is false
and state.globalFilter
is changedmanualFilters
is false
and state.filters
is changedmanualGroupBy
is false
and state.groupBy
is changedfalse
paginateExpandedRows: Bool
useExpanded
plugin hook simultaneouslytrue
true
, expanded rows are paginated along with normal rows. This results in stable page sizes across every page.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
pageIndex
value, located on the state.state.pageSize: Int
pageSize
value, located on the state.page: Array<row>
pageIndex
value.pageCount: Int
manualPagination
is set to false
, this is the total amount of pages available in the table based on the current pageSize
valuemanualPagination
is set to true
, this is merely the same pageCount
option that was passed in the table options.pageOptions: Array<Int>
canPreviousPage: Bool
pageIndex
is greater than 0
, this will be true
canNextPage:
pageIndex
is less than pageCount
, this will be true
gotoPage: Function(pageIndex)
pageIndex
, will set pageIndex
to that value.pageIndex
range, then this function will do nothing.previousPage: Function
state.pageIndex
by one.canPreviousPage
is false, this function will do nothing.nextPage: Function
state.pageIndex
by one.canNextPage
is false, this function will do nothing.setPageSize: Function(pageSize)
state.pageSize
to the new value.state.pageIndex
is also calculated. It is calculated via Math.floor(currentTopRowIndex / newPageSize)
The best JavaScript newsletter! Delivered every Monday to over 76,000 devs.