usePagination
DataTable
stable
Suite of three pagination helpers for OrigamDataTable: createPagination initialises page and itemsPerPage refs from props; providePagination computes derived state (startIndex, stopIndex, pageCount) and provides it to children; usePagination injects the provided pagination context. A fourth helper usePaginatedItems slices the items array for the current page.
API
Signature
Full TypeScript signature sourced from the composable file.
Consumed interfaces
IDataTablePaginationProps
IDataTableProvidePagination
IDataTableGroup
API
Parameters
Input parameters accepted by this composable.
- propsrequiredIDataTablePaginationProps
- Component props containing page and itemsPerPage (for createPagination).
- options.pagerequiredRef<number>
- Active page (1-based). Auto-clamped to [1, pageCount] when itemsLength or itemsPerPage changes.
- options.itemsPerPagerequiredRef<number>
- Rows per page. -1 = show all.
- options.itemsLengthrequiredRef<number>
- Total number of items (server-side count or items.length for client-side).
API
Return values
Properties and methods exposed by the composable return object.
- page
- Current page, two-way bound via useVModel.
- itemsPerPage
- Rows per page, two-way bound.
- startIndex
- Inclusive start index in the full items array for the active page.
- stopIndex
- Exclusive stop index. slice(startIndex, stopIndex) gives the current page.
- pageCount
- Total number of pages. Always at least 1. Equals 1 when itemsPerPage is -1.
- nextPage
- Advances to the next page, clamped to pageCount.
- prevPage
- Goes back one page, minimum 1.
- setPage
- Jumps to an arbitrary page, clamped to [1, pageCount].
- setItemsPerPage
- Changes the page size and resets to page 1.
Usage
Examples
Ready-to-paste usage snippets.
Client-side paginated table
Custom pagination footer