Pagination
Enable it with :pagination="{}". It is off by default: when omitted or false, the table keeps showing all the data. The configuration follows ant-design-vue 4.2.6, while change keeps this library's three-argument signature.
Local pagination
The component filters and sorts first, then paginates by root records, and finally expands tree nodes. Children and expanded content do not consume additional page slots. Configure a stable rowKey to keep selection and expansion state across pages.
Data can come from a static array or an API that returns all records at once. For example, 20 records with defaultPageSize: 10 automatically produce two pages. Page changes do not request again unless their events are connected to a request function. See Load all records, then process locally for local sorting, filtering and a request counter.
Local pagination usually omits total, letting the component use the filtered record count. When loading through useTableRequest, you can bind only its data and loading state and provide independent local pagination, without the Hook's pagination, manual or onChange. See Choose where data is processed for the complete setups.
The demo also enables row selection: the header checkbox selects the current page, while the "Select all data" menu item selects all loaded, selectable records after filtering. After changing pages, check the selection scope through the selected count and the checkbox states.
Pagination-only callback
If you only need pagination, use TablePaginationConfig.onChange directly. Its arguments are (page: number, pageSize: number); you do not need to handle the table's filters or sorter. Below is a complete controlled pagination example that gets its parameter types through NonNullable<TablePaginationConfig['onChange']>.
Controlled pagination
current and pageSize can be controlled independently. When omitted, internal state is used, and defaultCurrent and defaultPageSize initialize it only once. The parent component must accept the new state in the callback; the component never mutates the configuration object. The top and bottom pagers share the same state.
Remote pagination
Pass the current page's records and full total, and explicitly set :manual="{ pagination: true }". The component uses the server total, including 0, without slicing again. Application event handling decides whether a page change sends a request; total alone is not a network request switch.
Requests can be managed by application code, or you can use useTableRequest request management. When you manage them yourself, keep the total during loading, and use request sequence numbers or AbortController to prevent stale responses from overwriting the new page.
sorter: true still sorts locally by default. If the server also sorts and filters, use :manual="{ pagination: true, sort: true, filter: true }" or :manual="true". Omitted fields in the object are treated as false. Fully remote setups can bind the manual returned by useTableRequest; mixed setups also need to connect requests by action.
Compatibility when manual.pagination is not explicitly enabled
Without manual.pagination, when the processed record count is below total and does not exceed pageSize, the component accepts current-page data without slicing again. When the record count exceeds pageSize but is below total, it warns and slices locally. In this mode, a missing positive integer total falls back to the processed root record count. With manual.pagination explicitly enabled, a valid total: 0 is preserved without that fallback.
For new remote pagination setups, explicitly configure manual.pagination instead of relying on record counts to infer how data is processed.
The demo below enables preserveSelectedRowKeys and shows the selected count and record names across pages. Select a record, change pages and select more, then return to the original page to check the checkbox state. "Select all data" only affects loaded data and does not request other pages.
Controlled selectedRowKeys are not automatically pruned when paging replaces the data source, even without preserve enabled. In that case, however, selection callbacks return only selected rows in the current dataSource. Set preserveSelectedRowKeys: true to cache selected records from earlier pages for callbacks. Uncontrolled mode prunes absent keys when preserve is not enabled. To clear controlled selection on page changes, application code must explicitly clear the keys and any selected records it stores. See Pagination and cross-page selection.
Composable layouts and content slots
pagination.layout uses the same API under both presets. An ordered array determines the order of the controls; { left, right } places content on the left and right sides 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 only:
// layout: ['sizes', 'prev', 'pager', 'next', 'total']The built-in items are total, sizes, prev, pager, next and jumper. pager contains the numbered pages and the ellipsis jump buttons, or the current-page input and the page count in simple mode; the previous and next buttons are controlled by prev and next respectively. Element's native comma-separated strings, '->' and bare 'slot' are not part of this library's layout syntax.
Array layouts keep using the top / bottom position and the Left / Center / Right alignment from position. A left-right layout fills the pagination row: position only decides top or bottom, and the content inside aligns by left / right; when only one side is passed, the other side is not filled in automatically. Both regions can wrap, and the right region stays right-aligned after wrapping. In very narrow containers, control the width with pagerCount, simple or the styles of your application content.
Put { slot: 'selection' } in the layout, then tell the content apart with name in #paginationItem. The demo below supports switching between reordering, left-right regions, top and bottom pagers and a narrow container: the selection state is maintained by the parent component, refresh calls an application function and updates the Revision of the current page, and the counter lets you check that refreshing and switching layouts do not trigger pagination callbacks.
Layout and visibility rules
- When
layoutis omitted, each preset keeps its original order and visibility behavior; an explicit layout renders only the listed items and does not append controls automatically. showTotal,showSizeChangerandshowQuickJumperstill control visibility. Listingsizesdoes not overrideshowSizeChanger: false, and listingjumperdoes not enable quick jumping automatically. When its switch is not specified,sizesstill uses the existing total threshold.simplestill hidestotalandsizes, andjumpershows only a configured Go button. Whenpageris omitted, a Go button with no input to submit is not kept.- Switching layouts dynamically does not change the page, the page size or the data slice, and triggers neither pagination events nor the table-level
changeevent.itemRenderandbuildOptionTextkeep working. - When pagination is off,
position: ['none']is set, the effective total is 0 orhideOnSinglePageapplies, the pager and the application slots are hidden together. Withlayout: [],layout: {}, empty regions or all content hidden, no empty container is kept, but pagination state and data slicing still apply. A refresh action that must remain available with empty data should go intitle,footeror an external toolbar. - Duplicate built-in items and extension points with the same name keep only their first occurrence (left before right). Invalid items, blank slot names and extension points without
#paginationItemare skipped with a warning in development; a wrong top-level or region type, or unknown fields other thanleft/rightin the region object, warn and fall back to the default layout as a whole.{}is still a valid empty layout. When a slot deliberately returns empty content, no placeholder is left and no warning is shown.
Pagination content slot
The parameter type of #paginationItem is TablePaginationSlotProps, which contains the readonly effective state:
| Field | Type | Description |
|---|---|---|
name | string | Name from { slot: 'name' }. |
current | number | Current page. |
pageSize | number | Page size. |
total | number | Record count. |
pageCount | number | Page count, the same one the built-in pager uses. |
range | readonly [number, number] | Range of the current page, one-based, 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 it sits in, within an array layout or a left / right split. |
Application state such as the selected count references the parent component's data directly. The context does not contain refresh, paging or request functions; application actions are handled by you and do not trigger pagination events automatically. When pagers are shown at both the top and the bottom, an extension point with the same name renders once in each pager and receives its own position.
The layout types TablePaginationBuiltinLayoutItem, TablePaginationLayoutItem, TablePaginationLayout and TablePaginationSlotProps can all be imported from @vtable-guild/vtable-guild.
API
Props
| Prop | Type | Default | Description |
|---|---|---|---|
pagination | false | TablePaginationConfig | false | Pass {} to enable local or remote pagination; see Pagination. |
scroll | object | - | Horizontal and vertical scrolling; see options. Providing y creates a scroll area with a fixed header. |
manual | boolean | TableManualConfig | false | true skips local sorting, filtering and pagination slicing; the object form sets sort, filter and pagination separately, with omitted fields treated as false. Controls local computation only; it neither sends nor prevents requests. Header state and the change event keep working; see Choosing a processing mode. |
Events
| Event | Payload | Description |
|---|---|---|
change | (filters: TableFiltersInfo, sorter: VTableSorterResult<TRecord>, extra: TableChangeExtra<TRecord>) => void | Single event outlet after sorting, filtering, selection and pagination; extra.action is 'sort', 'filter', 'select' or 'paginate'. |
Slots
| Slot | Payload type | Description |
|---|---|---|
paginationItem | TablePaginationSlotProps | Renders application content for the pagination at { slot: 'name' } in pagination.layout. |
Configuration reference
Fields of the pagination object (TablePaginationConfig).
| Field | Type | Default | Description |
|---|---|---|---|
current | number | - | Controlled page. |
defaultCurrent | number | 1 | Initial page. |
pageSize | number | - | Controlled page size. |
defaultPageSize | number | 10 | Initial page size. |
total | number | - | Record count; when omitted or not a positive integer, the processed root record count is used. |
disabled | boolean | false | Disable pagination interaction; slicing still applies. |
hideOnSinglePage | boolean | false | Hide the pager when there is one page; a total of 0 always hides it. |
showSizeChanger | boolean | - | Show the page-size changer; when unset it appears once the total exceeds the threshold in the next row. |
totalBoundaryShowSizeChanger | number | 50 | Total above which the page-size changer appears automatically. |
pageSizeOptions | (string | number)[] | 10, 20, 50, 100 | Page-size options; the current size is still shown when it is not listed. |
buildOptionText | (option: { value: string | number }) => VNodeChild | - | Custom content for page-size options. |
showQuickJumper | boolean | { goButton?: VNodeChild } | false | Quick jumper. Submits on Enter or blur; with goButton, blur does not submit. |
showTotal | (total: number, range: [number, number]) => VNodeChild | - | Show the total; the range is one-based and [0, 0] for empty data. |
size | 'default' | 'small' | follows table size | Pager size. |
simple | boolean | false | Simple mode with an input instead of the page list. |
showLessItems | boolean | false | Use a smaller page window. |
pagerCount | number | - | Number of page buttons, an odd integer from 5 to 21; takes precedence over showLessItems. See page window. |
responsive | boolean | false | When size is not set, use the compact size on viewports narrower than 576px. |
itemRender | (item: { page: number; type: PaginationItemType; originalElement: VNodeChild }) => VNodeChild | - | Custom page and navigation buttons; type is page, prev, next, jump-prev or jump-next. |
position | TablePaginationPosition[] | bottom right | Pager positions, ['bottomRight'] by default; top and bottom can both be used. ['none'] hides the pager but keeps pagination. |
layout | TablePaginationLayout | preset layout | Ordered array or { left, right }; see composable layouts. |
locale | object | - | Pagination text overrides; fields are listed in the type declarations. |
class | string | - | Class for the pagination area. |
style | CSSProperties | - | Inline style for the pagination area. |
onChange | (page: number, pageSize: number) => void | - | Called on page changes, page-size changes and page resets caused by filtering. |
onShowSizeChange | (current: number, size: number) => void | - | Called when the page size changes. |
onUpdate:current | (current: number) => void | - | Update notification for the controlled page. |
onUpdate:pageSize | (pageSize: number) => void | - | Update notification for the controlled page size. |
Supported positions are topLeft, topCenter, topRight, bottomLeft, bottomCenter, bottomRight and none. Each region holds at most one pager and uses the first matching item in the array.
Page button count
pagerCount includes the first and last numbered pages and excludes the ellipses and the previous / next buttons; when there are fewer pages in total, all of them are shown. When it is set explicitly, both presets use the Element Plus pager algorithm, and the ellipses jump pagerCount - 2 pages backward or forward.
<VTable :pagination="{ pagerCount: 9 }" />pagerCount takes precedence over showLessItems. When it is not specified, each preset keeps its existing default / compact arrangement and 5 / 3-page jumps. Only odd integers from 5 to 21 are accepted; invalid values warn in development and fall back to the unspecified behavior. simple mode shows no page list and therefore ignores both options. Changing the page window dynamically does not change the current page, the page size or the data slice, and triggers no pagination events.
Element Plus's native pager-count validation only warns in development; invalid values still take part in the pager calculation, so you may see out-of-range values take effect in its Playground. VTable Guild falls back to the unspecified rules for invalid values in every environment and warns in development.
Advanced configuration and theming
Customize with theme.pagination.slots / variants and the --vtg-pagination-* tokens; both presets support them. A global locale pack can contain an optional pagination group, or you can use localeOverrides.pagination; the per-instance pagination.locale overrides last. Existing locale packs do not need new fields.
The layout structure can be customized through theme.pagination.slots.layout, left, right and extension; the spacing between the two regions and between extension points reuses --vtg-pagination-gap. Consecutive previous / pager / next items still use the existing pages slot and keep each preset's navigation spacing.
The ellipsis jump text can be customized through the optional locale fields prev_pages / next_pages; {count} in the template is replaced with the actual jump distance, for example prev_pages: 'Previous {count} pages'. Jumps of 3 / 5 pages keep using the existing prev_3 / next_3 and prev_5 / next_5 fields. The button's title and aria-label use the same text.
Element Plus preset
Pagination configuration and events keep using the Ant-style API above, and the two presets share the same default visibility rules and page-size options. After switching to element-plus, the pagination visuals and interaction follow Element Plus:
- Page buttons sit next to each other with no gap, and the current page is bold with no border; when
layoutis omitted, the total, page-size select, pager and jumper are arranged in that order. - When
pagerCountis not specified, the native 7-page window is used, andshowLessItems: truemaps to a 5-page window; the ellipses jump 5 / 3 pages backward or forward respectively. - The quick-jump input shows the current page; Enter or blur submits and restores the effective page, and decimals keep only their integer part; when a Go button is configured, submission still happens through the button or Enter.
- The Chinese jump text is "前往", and English does not show the
Pageafter the input; per-instance locale overrides still apply. - Default pagination buttons are 32px, and
size: 'small'is 24px with a 12px font size; when no pagination size is specified, asmalltable maps to compact pagination, andmiddle/largemap to default pagination.
Shared extensions such as simple, the Go button and itemRender remain available. Element's native string layout should be migrated to the array or left-right region object described above; currentPage / pageSizes correspond to current / pageSizeOptions respectively.
Ant's internal selectComponentClass, selectPrefixCls and prefixCls are not supported; use this project's theme, classPrefix and the table-level getPopupContainer. The first version does not export a standalone Pagination component.
The table below lists the styling entry points of the pager and the page-size menu. Override classes through the global theme.pagination; for per-instance styles use pagination.class or pagination.style.
ui slots
| Theme config | Slot | Description |
|---|---|---|
theme.pagination | root | Pagination root container. |
theme.pagination | layout | Two-region container of a custom pagination layout. |
theme.pagination | left | Left region of the pagination layout. |
theme.pagination | right | Right region of the pagination layout. |
theme.pagination | extension | Container for custom pagination content. |
theme.pagination | pages | Container for page numbers and the previous / next navigation buttons. |
theme.pagination | item | Page number and navigation buttons. |
theme.pagination | active | Extra styles for the current page number. |
theme.pagination | jump | Button that skips a group of page numbers. |
theme.pagination | jumpEllipsis | Ellipsis in the jump button. |
theme.pagination | jumpIcon | Icon shown when the jump button is hovered. |
theme.pagination | controls | Area for controls such as page size and quick jump. |
theme.pagination | simpleControls | Simple mode controls area. |
theme.pagination | simpleInput | Extra styles for the page number input in simple mode. |
theme.pagination | slash | Separator between the current page and the total page count. |
theme.pagination | go | Quick jump confirm button. |
theme.pagination | input | Page number input. |
theme.pagination | select | Page size select button. |
theme.pagination | popup | Page size dropdown panel. |
theme.pagination | option | Page size dropdown option. |
theme.pagination | optionActive | Extra styles for the selected page size option. |
theme.pagination | total | Total count text. |
theme.pagination | icon | Pagination button icon. |
Preset defaults
The code lists the slots and variants you can override directly. When the pager is in simple mode and disabled, the presets also apply compound styles to the jump control.
createVTableGuild({
theme: {
pagination: {
slots: {
root: 'flex shrink-0 flex-wrap items-center gap-[var(--vtg-pagination-gap)] py-[var(--vtg-pagination-margin)] text-[length:var(--vtg-table-font-size)] text-[color:var(--color-on-surface)]',
layout: 'flex w-full min-w-0 flex-wrap items-center gap-[var(--vtg-pagination-gap)]',
left: 'flex min-w-0 max-w-full flex-wrap items-center gap-[var(--vtg-pagination-gap)]',
right: 'ml-auto flex min-w-0 max-w-full flex-wrap items-center justify-end gap-[var(--vtg-pagination-gap)]',
extension: 'min-w-0 max-w-full break-words',
pages: 'flex items-center gap-[var(--vtg-pagination-gap)]',
item: 'inline-flex box-border shrink-0 items-center justify-center h-[var(--vtg-pagination-size)] min-w-[var(--vtg-pagination-size)] px-1 border border-[color:var(--vtg-pagination-border)] rounded-[var(--vtg-pagination-radius)] bg-[color:var(--vtg-pagination-bg)] text-inherit cursor-pointer transition-colors [&:not([aria-disabled=true]):hover]:text-[color:var(--vtg-pagination-hover-color)] [&:not([aria-disabled=true]):hover]:bg-[color:var(--vtg-pagination-hover-bg)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)] aria-disabled:cursor-not-allowed aria-disabled:text-[color:var(--color-text-disabled)] aria-disabled:border-[color:var(--vtg-pagination-border)] aria-disabled:bg-[color:var(--vtg-pagination-bg)] disabled:cursor-not-allowed disabled:text-[color:var(--color-text-disabled)] disabled:border-[color:var(--vtg-pagination-border)] disabled:bg-[color:var(--vtg-pagination-bg)]',
active: 'font-[number:var(--vtg-pagination-active-weight)] text-[color:var(--vtg-pagination-active-color)] border-[color:var(--vtg-pagination-active-border)] bg-[color:var(--vtg-pagination-active-bg)] [&:not([aria-disabled=true]):hover]:bg-[color:var(--vtg-pagination-active-bg)] [&:not([aria-disabled=true]):hover]:text-[color:var(--vtg-pagination-active-hover-color)] [&:not([aria-disabled=true]):hover]:border-[color:var(--vtg-pagination-active-hover-color)] aria-disabled:border-[color:var(--color-border)] aria-disabled:bg-[color:var(--vtg-pagination-active-disabled-bg)] disabled:border-[color:var(--color-border)] disabled:bg-[color:var(--vtg-pagination-active-disabled-bg)]',
jump: 'group relative text-[color:var(--color-text-disabled)] [&:not([aria-disabled=true]):hover]:bg-transparent',
jumpEllipsis: 'transition-opacity duration-200 group-[:not([aria-disabled=true]):hover]:opacity-0 group-[:not([aria-disabled=true]):focus-visible]:opacity-0',
jumpIcon: 'absolute h-[var(--vtg-pagination-icon-size)] w-[var(--vtg-pagination-icon-size)] stroke-[1.5] text-[color:var(--color-primary)] opacity-0 transition-opacity duration-200 group-[:not([aria-disabled=true]):hover]:opacity-100 group-[:not([aria-disabled=true]):focus-visible]:opacity-100',
controls: 'flex items-center gap-[var(--vtg-pagination-gap)]',
simpleControls: 'flex items-center gap-[var(--vtg-pagination-gap)]',
simpleInput: 'w-[var(--vtg-pagination-simple-input-width)] enabled:hover:border-[color:var(--color-primary)] enabled:focus:border-[color:var(--color-primary-hover)]',
slash: 'mx-[var(--vtg-pagination-slash-margin)]',
go: 'inline-flex items-center justify-center h-[var(--vtg-pagination-size)] bg-transparent p-0 text-inherit cursor-pointer disabled:cursor-not-allowed',
input: 'box-border w-[var(--vtg-pagination-input-width)] h-[var(--vtg-pagination-size)] rounded-[var(--vtg-pagination-radius)] border border-[color:var(--color-border)] bg-[color:var(--color-surface)] px-1 text-center text-inherit outline-none transition-all duration-200 enabled:hover:border-[color:var(--color-primary-hover)] enabled:focus:border-[color:var(--color-primary)] enabled:focus:shadow-[var(--vtg-pagination-focus-shadow)] disabled:cursor-not-allowed disabled:text-[color:var(--color-text-disabled)] disabled:bg-[color:var(--color-bg-disabled)]',
select: 'inline-flex items-center justify-between gap-2 whitespace-nowrap px-[var(--vtg-pagination-select-padding)] border-[color:var(--color-border)] bg-[color:var(--color-surface)] [&:not([aria-disabled=true]):hover]:bg-[color:var(--color-surface)] [&:not([aria-disabled=true]):hover]:text-inherit [&:not([aria-disabled=true]):hover]:border-[color:var(--color-primary-hover)] aria-expanded:border-[color:var(--color-primary)] aria-expanded:shadow-[var(--vtg-pagination-focus-shadow)] disabled:bg-[color:var(--color-bg-disabled)] disabled:border-[color:var(--color-border)] [&_svg]:text-[color:var(--color-text-placeholder)]',
popup: 'list-none [--vtg-table-popup-panel-radius:var(--vtg-pagination-popup-radius)] [--vtg-table-popup-panel-shadow:var(--vtg-pagination-popup-shadow)]',
option: 'flex min-h-[var(--vtg-pagination-option-height)] cursor-pointer items-center rounded leading-[22px] px-3 py-[5px] outline-none hover:bg-[color:var(--vtg-pagination-option-hover-bg)] focus:bg-[color:var(--vtg-pagination-option-hover-bg)]',
optionActive: 'font-[number:var(--vtg-pagination-active-weight)] text-[color:var(--vtg-pagination-option-active-color)] bg-[color:var(--vtg-pagination-option-active-bg)] hover:bg-[color:var(--vtg-pagination-option-active-bg)] focus:bg-[color:var(--vtg-pagination-option-active-bg)]',
total: 'whitespace-nowrap',
icon: 'inline-block h-[var(--vtg-pagination-icon-size)] w-[var(--vtg-pagination-icon-size)] stroke-[1.5]',
},
variants: {
size: {
small: {
root: '[--vtg-pagination-size:var(--vtg-pagination-size-sm)]',
},
},
align: {
left: {
root: 'justify-start',
},
center: {
root: 'justify-center',
},
right: {
root: 'justify-end',
},
},
simple: {
true: {
root: '[--vtg-pagination-size:var(--vtg-pagination-size-sm)]',
},
},
},
defaultVariants: {
size: 'default',
align: 'right',
},
},
},
})createVTableGuild({
themePreset: 'element-plus',
theme: {
pagination: {
slots: {
root: 'flex shrink-0 items-center gap-[var(--vtg-pagination-gap)] py-[var(--vtg-pagination-margin)] text-[length:var(--vtg-pagination-font-size)] text-[color:var(--color-on-surface)]',
layout: 'flex w-full min-w-0 flex-wrap items-center gap-[var(--vtg-pagination-gap)]',
left: 'flex min-w-0 max-w-full flex-wrap items-center gap-[var(--vtg-pagination-gap)]',
right: 'ml-auto flex min-w-0 max-w-full flex-wrap items-center justify-end gap-[var(--vtg-pagination-gap)]',
extension: 'min-w-0 max-w-full break-words',
pages: 'flex items-center gap-[var(--vtg-pagination-page-gap)]',
item: 'inline-flex box-border shrink-0 items-center justify-center h-[var(--vtg-pagination-size)] min-w-[var(--vtg-pagination-size)] px-1 border border-[color:var(--vtg-pagination-border)] rounded-[var(--vtg-pagination-radius)] bg-[color:var(--vtg-pagination-bg)] text-inherit cursor-pointer transition-colors [&:not([aria-disabled=true]):hover]:text-[color:var(--vtg-pagination-hover-color)] [&:not([aria-disabled=true]):hover]:bg-[color:var(--vtg-pagination-hover-bg)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)] aria-disabled:cursor-not-allowed aria-disabled:text-[color:var(--color-text-disabled)] aria-disabled:border-[color:var(--vtg-pagination-border)] aria-disabled:bg-[color:var(--vtg-pagination-bg)] disabled:cursor-not-allowed disabled:text-[color:var(--color-text-disabled)] disabled:border-[color:var(--vtg-pagination-border)] disabled:bg-[color:var(--vtg-pagination-bg)] border-0 focus-visible:outline-1 focus-visible:-outline-offset-1 aria-disabled:text-[color:var(--color-text-placeholder)] disabled:text-[color:var(--color-text-placeholder)]',
active: 'font-[number:var(--vtg-pagination-active-weight)] text-[color:var(--vtg-pagination-active-color)] bg-[color:var(--vtg-pagination-active-bg)] cursor-default [&:not([aria-disabled=true]):hover]:text-[color:var(--vtg-pagination-active-color)] [&:not([aria-disabled=true]):hover]:bg-[color:var(--vtg-pagination-active-bg)] aria-disabled:text-[color:var(--color-muted)] aria-disabled:bg-[color:var(--vtg-pagination-active-disabled-bg)] disabled:text-[color:var(--color-muted)] disabled:bg-[color:var(--vtg-pagination-active-disabled-bg)]',
jump: 'group relative [&:not([aria-disabled=true]):hover]:text-[color:var(--color-primary)]',
jumpEllipsis: 'transition-opacity duration-200 group-[:not([aria-disabled=true]):hover]:opacity-0 group-[:not([aria-disabled=true]):focus-visible]:opacity-0',
jumpIcon: 'absolute h-[var(--vtg-pagination-icon-size)] w-[var(--vtg-pagination-icon-size)] stroke-[1.5] text-[color:var(--color-primary)] opacity-0 transition-opacity duration-200 group-[:not([aria-disabled=true]):hover]:opacity-100 group-[:not([aria-disabled=true]):focus-visible]:opacity-100',
controls: 'flex items-center gap-[var(--vtg-pagination-control-gap)] text-[color:var(--color-text-regular)]',
simpleControls: 'flex items-center gap-[var(--vtg-pagination-gap)]',
simpleInput: 'w-[var(--vtg-pagination-simple-input-width)] enabled:hover:border-[color:var(--color-primary)] enabled:focus:border-[color:var(--color-primary-hover)]',
slash: 'mx-[var(--vtg-pagination-slash-margin)]',
go: 'inline-flex items-center justify-center h-[var(--vtg-pagination-size)] bg-transparent p-0 text-inherit cursor-pointer disabled:cursor-not-allowed',
input: 'box-border w-[var(--vtg-pagination-input-width)] h-[var(--vtg-pagination-size)] rounded-[var(--vtg-pagination-radius)] border border-[color:var(--color-border)] bg-[color:var(--color-surface)] px-1 text-center text-inherit outline-none transition-all duration-200 enabled:hover:border-[color:var(--color-primary-hover)] enabled:focus:border-[color:var(--color-primary)] enabled:focus:shadow-[var(--vtg-pagination-focus-shadow)] disabled:cursor-not-allowed disabled:text-[color:var(--color-text-disabled)] disabled:bg-[color:var(--color-bg-disabled)] rounded-[var(--vtg-input-border-radius)] text-[color:var(--color-text-regular)] [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none enabled:hover:border-[color:var(--color-border-hover)] enabled:focus:border-[color:var(--color-primary)] enabled:focus:shadow-none',
select: 'inline-flex items-center justify-between gap-2 whitespace-nowrap px-[var(--vtg-pagination-select-padding)] border-[color:var(--color-border)] bg-[color:var(--color-surface)] [&:not([aria-disabled=true]):hover]:bg-[color:var(--color-surface)] [&:not([aria-disabled=true]):hover]:text-inherit [&:not([aria-disabled=true]):hover]:border-[color:var(--color-primary-hover)] aria-expanded:border-[color:var(--color-primary)] aria-expanded:shadow-[var(--vtg-pagination-focus-shadow)] disabled:bg-[color:var(--color-bg-disabled)] disabled:border-[color:var(--color-border)] [&_svg]:text-[color:var(--color-text-placeholder)] border w-[var(--vtg-pagination-select-width)] rounded-[var(--vtg-input-border-radius)] text-[color:var(--color-text-regular)] [&:not([aria-disabled=true]):hover]:border-[color:var(--color-border-hover)] aria-expanded:shadow-none [&_svg]:transition-transform aria-expanded:[&_svg]:rotate-180',
popup: 'list-none [--vtg-table-popup-panel-radius:var(--vtg-pagination-popup-radius)] [--vtg-table-popup-panel-shadow:var(--vtg-pagination-popup-shadow)]',
option: 'flex min-h-[var(--vtg-pagination-option-height)] cursor-pointer items-center px-5 text-[color:var(--color-text-regular)] outline-none hover:bg-[color:var(--vtg-pagination-option-hover-bg)] focus:bg-[color:var(--vtg-pagination-option-hover-bg)]',
optionActive: 'font-[number:var(--vtg-pagination-active-weight)] text-[color:var(--vtg-pagination-option-active-color)] bg-transparent hover:bg-[color:var(--vtg-pagination-option-hover-bg)] focus:bg-[color:var(--vtg-pagination-option-hover-bg)]',
total: 'whitespace-nowrap text-[color:var(--color-text-regular)]',
icon: 'inline-block h-[var(--vtg-pagination-icon-size)] w-[var(--vtg-pagination-icon-size)] stroke-[1.5]',
},
variants: {
size: {
small: {
root: '[--vtg-pagination-size:var(--vtg-pagination-size-sm)] [--vtg-pagination-font-size:var(--vtg-pagination-font-size-sm)] [--vtg-pagination-select-width:var(--vtg-pagination-select-width-sm)]',
},
},
align: {
left: {
root: 'justify-start',
},
center: {
root: 'justify-center',
},
right: {
root: 'justify-end',
},
},
simple: {
true: {
root: '[--vtg-pagination-size:var(--vtg-pagination-size-sm)]',
},
},
},
defaultVariants: {
size: 'default',
align: 'right',
},
},
},
})CSS variables
| Variable | Purpose | antdv | element-plus |
|---|---|---|---|
--vtg-pagination-size | Button height and minimum width at the default size | 32px | 32px |
--vtg-pagination-size-sm | Button height and minimum width at the small size | 24px | 24px |
--vtg-pagination-gap | Gap between the navigation, controls and custom layout regions | 8px | 16px |
--vtg-pagination-margin | Vertical padding of the pagination container | 16px | 16px |
--vtg-pagination-radius | Radius of buttons and inputs | 6px | 2px |
--vtg-pagination-input-width | Quick jump input width | 50px | 56px |
--vtg-pagination-border | Default border color of page number buttons | transparent | transparent |
--vtg-pagination-bg | Default background of page number buttons | transparent | var(--color-surface) |
--vtg-pagination-active-bg | Current page number background | var(--color-surface) | var(--color-surface) |
--vtg-pagination-active-color | Current page number text color | var(--color-primary) | var(--color-primary) |
--vtg-pagination-active-border | Current page number button border color | var(--color-primary) | transparent |
--vtg-pagination-popup-z | Page size dropdown panel z-index | 1050 | 2000 |
--vtg-pagination-popup-radius | Page size dropdown panel radius | var(--vtg-table-popup-radius) | var(--vtg-table-popup-radius) |
--vtg-pagination-popup-shadow | Page size dropdown panel shadow | var(--vtg-table-popup-shadow) | var(--vtg-table-popup-shadow) |
--vtg-pagination-font-size | Default pagination font size | not read | 14px |
--vtg-pagination-font-size-sm | Small-size pagination font size | not read | 12px |
--vtg-pagination-page-gap | Gap between adjacent page numbers | not read | 0px |
--vtg-pagination-control-gap | Gap between controls such as quick jump | not read | 8px |
--vtg-pagination-select-width | Page size selector width | not read | 128px |
--vtg-pagination-select-width-sm | Page size selector width at the small size | not read | 100px |
--vtg-table-popup-radius | Radius of table popups such as filtering and batch selection | 6px | 2px |
--vtg-table-popup-border | Table popup border | 0 | 1px solid var(--vtg-border-color-lighter, var(--color-default)) |
--vtg-table-popup-padding-block | Table popup vertical padding | 4px | 5px |
--vtg-table-popup-padding-inline | Table popup horizontal padding | 4px | 0px |
--vtg-table-popup-shadow | Table popup shadow | 0 6px 16px rgb(0 0 0 / 8%), 0 3px 6px -4px rgb(0 0 0 / 12%), 0 9px 28px 8px rgb(0 0 0 / 5%) | 0 0 12px rgb(0 0 0 / 12%) |
Events and other features
The arguments of the table's change are (filters: TableFiltersInfo, sorter: VTableSorterResult<Row>, extra: TableChangeExtra<Row>), which differ from the pagination-only callback above. extra.pagination?: TablePaginationState contains current, pageSize and total. Use the public callback type to infer all the parameters automatically:
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
}- The argument order of
change(filters, sorter, extra)is unchanged. With pagination enabled, every action carriesextra.pagination; when it is not enabled, the field is not added.'paginate'is a new action, so exhaustive checks need this branch. - Changing the page and changing the page size each trigger one table event; filtering returns to page 1 and triggers only
'filter'. Sorting keeps the page; a page-size change keeps the page and clamps it to the last page when necessary. - For sorting, filtering and pagination,
currentDataSourceis the processed data before pagination; in remote scenarios it contains only loaded records.selectkeeps its existing displayed-data semantics. - When the data shrinks, the effective page clamps to the last page, and external prop updates do not trigger events in return. If a new request is needed after the remote total shrinks, application code is responsible for it.
- Header select-all, invert and Shift range selection are limited to the current page; the "Select all data" menu item selects all loaded records. Application code owns controlled keys;
preserveSelectedRowKeysretains uncontrolled keys across pages and caches selected records without requesting unloaded pages. title/footerreceive the displayed data of the current page. Dragging happens only within the current page but returns the complete inputdataSource.- The pager does not scroll horizontally with the body.
scroll.y: 'auto'automatically reserves space for the top and bottom pagers and is compatible with virtual scrolling. - With pagination enabled, paginating / filtering / sorting scrolls back to the top of the body by default and keeps the horizontal position. Turn it off with
scroll.scrollToFirstRowOnChange: false; without pagination, the existing scroll behavior is kept by default.
When migrating from Ant, read what used to be the first argument of the four-argument callback from extra.pagination instead; pass a pagination object explicitly to enable the feature.
Type Declarations
The following types are all imported from @vtable-guild/vtable-guild. TRecord is your application's row type; Vue rendering types such as VNodeChild are imported from vue. For the column, sorter and base types that the declarations depend on, see the Type reference.
View 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
}