Pagination
Opt in with :pagination="{}". Omitted or false preserves the existing unpaginated behavior. Configuration follows Ant Design Vue 4.2.6, while the table keeps change(filters, sorter, extra).
Local and controlled data
The pipeline is filter → sort → paginate root records → expand trees → render. Children and expanded detail rows do not consume additional page slots. Provide a stable rowKey for selection and expansion.
This demo also enables row selection: the header checkbox selects the current page, while “Select all data” selects all loaded, selectable records after filtering. Change pages and inspect the selected count and checkboxes to compare their scope.
Control current and pageSize independently, or initialize internal state once with defaultCurrent (1) and defaultPageSize (10). Props are never mutated. Parent components must accept requested changes. Both pagers share state.
Pagination-only callback
If you only need pagination, use TablePaginationConfig.onChange. Its arguments are (page: number, pageSize: number); you do not need table filters or sorter parameters. The complete example below provides its callback type through NonNullable<TablePaginationConfig['onChange']>.
Remote data
Pass one page plus total. If processed data length is below total and does not exceed pageSize, it is rendered without another slice. A length between pageSize and total warns and uses local slicing. A missing or invalid positive integer total falls back to the processed root count.
The component does not fetch data. Keep total during loading and reject stale responses with request IDs or AbortController. For server sorting use sorter: true; for server filtering omit local onFilter. Handle the corresponding table action in your request code.
The remote demo enables preserveSelectedRowKeys and displays the selected count and record names across pages. Select a row, select another on a different page, then return to verify the first selection. “Select all data” only affects loaded records and never fetches other pages.
Composable layouts and content slots
Both presets accept the same pagination.layout API. An ordered array arranges a single group; { left, right } places content on either side of the pagination row:
import type { TablePaginationConfig } from '@vtable-guild/vtable-guild'
const pagination: TablePaginationConfig = {
showTotal: (total) => `${total} records`,
showSizeChanger: true,
showQuickJumper: true,
layout: {
left: [{ slot: 'selection' }, 'total'],
right: ['sizes', 'prev', 'pager', 'next', 'jumper', { slot: 'refresh' }],
},
}
// To reorder a single group:
// layout: ['sizes', 'prev', 'pager', 'next', 'total']Built-in items are total, sizes, prev, pager, next and jumper. pager contains numbered pages and ellipsis jump buttons, or the current-page input and page count in simple mode. Previous and next buttons are separate items. Element's comma-delimited strings, '->' and bare 'slot' are not accepted.
Arrays retain the top/bottom position and Left/Center/Right alignment from position. A split layout fills the pagination row: position selects only top or bottom, while left and right determine internal alignment. An omitted side stays empty. Both regions can wrap, with the right region still aligned right after wrapping. Use pagerCount, simple or application content styles for very narrow containers.
Place { slot: 'selection' } in the layout and branch on name in #paginationItem. This demo supports reordered, split, top/bottom and narrow layouts. Selection belongs to the parent, and refresh updates the current page's Revision through application code. The callback counter verifies that refreshing or changing layouts does not emit pagination changes.
Layout and visibility rules
- Omit
layoutto preserve each preset's existing order and visibility behavior. Explicit layouts render only the listed items. showTotal,showSizeChangerandshowQuickJumperstill control visibility. Includingsizesdoes not overrideshowSizeChanger: false; includingjumperdoes not enable quick jumping. The size changer retains its existing total threshold when its switch is omitted.simplestill hidestotalandsizes;jumperonly renders an explicitly configured Go button. Omittingpageralso removes a Go button that would have no input to submit.- Changing layouts preserves the current page, page size and data slice, and emits no pagination callbacks or table
changeevents.itemRenderandbuildOptionTextretain their behavior. pagination: false,position: ['none'], an effective total of zero or an applicablehideOnSinglePagehide both pagination and extension content. Empty arrays, empty objects, empty regions and entirely hidden content leave no empty containers; pagination state and slicing remain active for empty layouts. Put actions that must remain available with empty data intitle,footeror an external toolbar.- Duplicate built-in items and slot names retain their first occurrence, visiting left before right. Invalid items, blank names and extensions without
#paginationItemare skipped with development warnings. Invalid top-level or region types, or unknown fields other thanleft/rightin a region object, warn and fall back to the entire default layout.{}remains a valid empty layout. A slot intentionally returning empty content leaves no wrapper and produces no warning.
Pagination slot context
#paginationItem receives TablePaginationSlotProps, a readonly view of effective state:
| Field | Type | Meaning |
|---|---|---|
name | string | Name from { slot: 'name' } |
current / pageSize / total | number | Current page, page size and record count |
pageCount | number | Page count used by the built-in pager |
range | readonly [number, number] | One-based page range, matching showTotal |
disabled | boolean | Whether pagination is disabled; bind this to application buttons as needed |
position | Exclude<TablePaginationPosition, 'none'> | Actual pager position, such as topLeft or bottomRight |
region | 'inline' | 'left' | 'right' | Region containing the extension |
Read application state, such as selected keys, directly from the parent. The context does not contain refresh, navigation or request methods; application actions do not automatically emit pagination events. When top and bottom pagers are both visible, each renders its own instance of an extension with the appropriate position.
Import TablePaginationBuiltinLayoutItem, TablePaginationLayoutItem, TablePaginationLayout and TablePaginationSlotProps from @vtable-guild/vtable-guild.
Configuration
| Field | Type / default | Purpose |
|---|---|---|
current, defaultCurrent | number / 1 | Controlled / initial page |
pageSize, defaultPageSize | number / 10 | Controlled / initial size |
total | number | Positive explicit total, otherwise processed root count |
disabled, hideOnSinglePage | boolean / false | Disable interaction / hide one-page controls; total zero hides the pager |
showSizeChanger | boolean | Defaults to total > 50 |
totalBoundaryShowSizeChanger | number / 50 | Threshold for automatic size changer |
pageSizeOptions | (string | number)[] | Defaults to ['10','20','50','100']; current size remains available |
buildOptionText | (option: { value: string | number }) => VNodeChild | Custom option content |
showQuickJumper | boolean | { goButton?: VNodeChild } | Submit on Enter/blur; with a Go button, blur does not submit |
showTotal | (total: number, range: [number, number]) => VNodeChild | One-based range; empty range is [0, 0] |
size | 'default' | 'small' | Follows table size when omitted |
simple, showLessItems | boolean / false | Input pager / smaller page window |
pagerCount | number | Odd integer 5–21; overrides showLessItems |
responsive | boolean / false | Compact size below 576px unless size is explicit |
itemRender | (item: { page: number; type: PaginationItemType; originalElement: VNodeChild }) => VNodeChild | Types: page, prev, next, jump-prev, jump-next |
position | TablePaginationPosition[] | Default ['bottomRight']; top/bottom Left/Center/Right or none |
layout | TablePaginationLayout | Ordered array or { left, right }; omitted keeps preset defaults; show switches still apply |
locale, class, style | Partial<VTableGuildPaginationLocale>, string, CSSProperties | Text and presentation overrides |
onChange | (page: number, pageSize: number) => void | Navigation, size changes and filter resets |
onShowSizeChange | (current: number, size: number) => void | Size changes |
'onUpdate:current', 'onUpdate:pageSize' | (value: number) => void | Controlled state update notifications |
Only the first matching position in each top/bottom region is used. position: ['none'] hides controls but retains slicing; pagination: false disables both.
Page window
pagerCount includes the first and last numbered pages, excluding ellipses and previous/next buttons. All pages appear when the total page count is smaller. When explicitly set, both presets use the Element Plus page-window algorithm, and ellipses jump pagerCount - 2 pages.
<VTable :pagination="{ pagerCount: 9 }" />pagerCount takes precedence over showLessItems. When omitted, each preset retains its existing default/compact window and 5/3-page jumps. Only odd integers from 5 through 21 are accepted; invalid values warn during development and fall back to the omitted-value behavior. simple has no numbered page list and ignores both options. Changing the page window does not change the current page, page size or data slice, and emits no pagination events.
Element Plus's native pager-count validation only warns during development; invalid values still participate in page-window calculations, so values outside the documented range may appear to work in its Playground. VTable Guild falls back to the omitted-value behavior in all environments and warns during development.
Events, migration and integration
The table change event receives (filters: TableFiltersInfo, sorter: VTableSorterResult<Row>, extra: TableChangeExtra<Row>). These differ from the pagination-only callback above. Its optional extra.pagination contains current, pageSize and total. Use the public callback type to infer all three parameters:
import { ref } from 'vue'
import type { VTableEventProps } from '@vtable-guild/vtable-guild'
interface Row {
key: number
name: string
}
const current = ref(1)
const pageSize = ref(10)
const handleChange: NonNullable<VTableEventProps<Row>['onChange']> = (_filters, _sorter, extra) => {
if (extra.action !== 'paginate' || !extra.pagination) return
current.value = extra.pagination.current
pageSize.value = extra.pagination.pageSize
}- Keep
change(filters, sorter, extra). Enabled pagination addsextra.pagination: { current, pageSize, total }. Handle the newextra.action === 'paginate'in exhaustive switches. - Pagination and size changes emit one table event. Filtering requests page 1 with one
filterevent. Sorting retains the page. Size changes keep the page or clamp to the last page. - Controlled values remain owned by the parent; callbacks report requested values. External updates do not emit events. Shrinking data clamps the effective page; refetch an adjusted remote page in application code if needed.
- For sort/filter/paginate,
currentDataSourcecontains processed data before pagination, limited to loaded records remotely. Selection retains its existing displayed-data semantics. - Header select-all, invert and Shift selection affect the current page. The “Select all data” menu affects all loaded records.
preserveSelectedRowKeysretains remote keys and previously loaded selected records. - Title/footer receive displayed page data. Row dragging remains within the page and returns the entire input dataSource. Tree expansion, virtual scrolling and automatic height are supported.
- Enabled pagination defaults to scrolling to the first row on sort/filter/paginate while keeping the horizontal offset. Set
scroll.scrollToFirstRowOnChange: falseto opt out. Unpaginated tables retain their old default. - When migrating from Ant, opt in explicitly and read the original first callback argument from
extra.pagination.
Themes and locales
Both presets use theme.pagination slots/variants and --vtg-pagination-* tokens: size, size-sm, gap, margin, radius, input-width, border, bg, active-bg, active-color, active-border, popup-z and popup-shadow. Semantic colors follow dark mode. Style generation supports prebuilt CSS and Tailwind 3/4 with custom class prefixes.
Customize layout structure with theme.pagination.slots.layout, left, right and extension. Regions and extensions reuse --vtg-pagination-gap. Consecutive previous/page/next items retain the existing pages slot and each preset's navigation spacing.
The element-plus preset retains the same Ant-style configuration, callbacks, visibility defaults and page-size options. It uses contiguous, borderless page buttons with a bold active page; without layout, the order is total, sizes, pages, jumper. With pagerCount omitted, its page window follows Element Plus (7, or 5 with showLessItems), with 5/3-page jumps. The quick-jump input shows the current page, truncates decimals on submission, and restores the effective page after Enter or blur; an explicit Go button retains the existing submission rules. Chinese uses “前往”; English omits the trailing “Page”. Default buttons are 32px; small buttons are 24px with 12px text. Without an explicit pagination size, small tables use small pagination, while middle/large tables use default pagination. simple, Go buttons and itemRender remain supported extensions.
To migrate Element's string layout, use the array or region object described above. Its currentPage and pageSizes correspond to current and pageSizeOptions.
Existing locale packs remain valid. Add an optional global pagination group or localeOverrides.pagination; table pagination.locale takes final precedence. Locale keys include items_per_page, jump_to, jump_to_confirm, page, prev_page, next_page, prev_3/next_3, prev_5/next_5, navigation and page_size.
Optional prev_pages / next_pages locale templates use {count} for the actual ellipsis jump distance, for example prev_pages: 'Previous {count} pages'. Jumps of 3 or 5 pages continue to use the existing prev_3 / next_3 and prev_5 / next_5 keys. Each jump button uses the same text for its title and aria-label.
Ant internal selectComponentClass, selectPrefixCls and prefixCls are unsupported. Use the existing theme system, classPrefix and table getPopupContainer. A standalone Pagination component is not exported.
Type Declarations
Import these types from @vtable-guild/vtable-guild. TRecord is the business row type; Vue rendering types such as VNodeChild come from vue. Column, sorter and other supporting declarations are indexed in the type reference (Chinese).
Show type declarations
export interface TablePaginationConfig {
current?: number
defaultCurrent?: number
pageSize?: number
defaultPageSize?: number
total?: number
disabled?: boolean
hideOnSinglePage?: boolean
showSizeChanger?: boolean
pageSizeOptions?: (string | number)[]
totalBoundaryShowSizeChanger?: number
buildOptionText?: (option: { value: string | number }) => VNodeChild
showQuickJumper?: boolean | { goButton?: VNodeChild }
showTotal?: (total: number, range: [number, number]) => VNodeChild
size?: 'default' | 'small'
simple?: boolean
showLessItems?: boolean
pagerCount?: number
responsive?: boolean
itemRender?: (item: {
page: number
type: PaginationItemType
originalElement: VNodeChild
}) => VNodeChild
locale?: Partial<VTableGuildPaginationLocale>
class?: string
style?: CSSProperties
position?: TablePaginationPosition[]
layout?: TablePaginationLayout
onChange?: (page: number, pageSize: number) => void
onShowSizeChange?: (current: number, size: number) => void
'onUpdate:current'?: (current: number) => void
'onUpdate:pageSize'?: (pageSize: number) => void
}export interface TablePaginationState {
current: number
pageSize: number
total: number
}export type TablePaginationPosition =
| 'topLeft'
| 'topCenter'
| 'topRight'
| 'bottomLeft'
| 'bottomCenter'
| 'bottomRight'
| 'none'export type PaginationItemType = 'page' | 'prev' | 'next' | 'jump-prev' | 'jump-next'export type TablePaginationBuiltinLayoutItem =
| 'total'
| 'sizes'
| 'prev'
| 'pager'
| 'next'
| 'jumper'export type TablePaginationLayoutItem = TablePaginationBuiltinLayoutItem | { readonly slot: string }export type TablePaginationLayout =
| readonly TablePaginationLayoutItem[]
| {
readonly left?: readonly TablePaginationLayoutItem[]
readonly right?: readonly TablePaginationLayoutItem[]
}export type TablePaginationSlotProps = Readonly<
TablePaginationState & {
name: string
pageCount: number
range: readonly [number, number]
disabled: boolean
position: Exclude<TablePaginationPosition, 'none'>
region: 'inline' | 'left' | 'right'
}
>export type TableFiltersInfo = Record<string, (string | number | boolean)[] | null>export interface SorterResultLike<TRecord extends object = Record<string, any>> {
column: ColumnType<TRecord> | undefined
columnKey: Key | undefined
order: SortOrder
field: ColumnType<TRecord>['dataIndex']
}export type VTableSorterResult<TRecord extends object = Record<string, any>> =
| SorterResultLike<TRecord>
| Array<SorterResultLike<TRecord>>export interface TableChangeExtra<TRecord extends object = Record<string, any>> {
action: 'sort' | 'filter' | 'select' | 'paginate'
/** Available only when pagination is enabled. */
pagination?: TablePaginationState
currentDataSource: TRecord[]
}export interface VTableEventProps<TRecord extends object = Record<string, any>> {
onChange?: (
filters: TableFiltersInfo,
sorter: VTableSorterResult<TRecord>,
extra: TableChangeExtra<TRecord>,
) => void
onResizeColumn?: (column: ColumnType<TRecord>, width: number) => void
onRowDragEnd?: (newData: TRecord[], info: RowDragSortInfo) => void
}export interface VTableGuildPaginationLocale {
items_per_page: string
jump_to: string
jump_to_confirm: string
page: string
prev_page: string
next_page: string
prev_5: string
next_5: string
prev_3: string
next_3: string
/** {count} 会被替换为跳转页数。 */
prev_pages?: string
next_pages?: string
navigation: string
page_size: string
}