Skip to content

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.

Edit in Playground

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']>.

Edit in Playground

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.

Edit in Playground

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.

Edit in Playground

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:

ts
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.

Edit in Playground

Layout and visibility rules ​

  • When layout is 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, showSizeChanger and showQuickJumper still control visibility. Listing sizes does not override showSizeChanger: false, and listing jumper does not enable quick jumping automatically. When its switch is not specified, sizes still uses the existing total threshold.
  • simple still hides total and sizes, and jumper shows only a configured Go button. When pager is 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 change event. itemRender and buildOptionText keep working.
  • When pagination is off, position: ['none'] is set, the effective total is 0 or hideOnSinglePage applies, the pager and the application slots are hidden together. With layout: [], 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 in title, footer or 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 #paginationItem are skipped with a warning in development; a wrong top-level or region type, or unknown fields other than left / right in 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:

FieldTypeDescription
namestringName from { slot: 'name' }.
currentnumberCurrent page.
pageSizenumberPage size.
totalnumberRecord count.
pageCountnumberPage count, the same one the built-in pager uses.
rangereadonly [number, number]Range of the current page, one-based, matching showTotal.
disabledbooleanWhether pagination is disabled; bind this to application buttons as needed.
positionExclude<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 ​

PropTypeDefaultDescription
paginationfalse | TablePaginationConfigfalsePass {} to enable local or remote pagination; see Pagination.
scrollobject-Horizontal and vertical scrolling; see options. Providing y creates a scroll area with a fixed header.
manualboolean | TableManualConfigfalsetrue 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 ​

EventPayloadDescription
change(filters: TableFiltersInfo, sorter: VTableSorterResult<TRecord>, extra: TableChangeExtra<TRecord>) => voidSingle event outlet after sorting, filtering, selection and pagination; extra.action is 'sort', 'filter', 'select' or 'paginate'.

Slots ​

SlotPayload typeDescription
paginationItemTablePaginationSlotPropsRenders application content for the pagination at { slot: 'name' } in pagination.layout.

Configuration reference ​

Fields of the pagination object (TablePaginationConfig).

FieldTypeDefaultDescription
currentnumber-Controlled page.
defaultCurrentnumber1Initial page.
pageSizenumber-Controlled page size.
defaultPageSizenumber10Initial page size.
totalnumber-Record count; when omitted or not a positive integer, the processed root record count is used.
disabledbooleanfalseDisable pagination interaction; slicing still applies.
hideOnSinglePagebooleanfalseHide the pager when there is one page; a total of 0 always hides it.
showSizeChangerboolean-Show the page-size changer; when unset it appears once the total exceeds the threshold in the next row.
totalBoundaryShowSizeChangernumber50Total above which the page-size changer appears automatically.
pageSizeOptions(string | number)[]10, 20, 50, 100Page-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.
showQuickJumperboolean | { goButton?: VNodeChild }falseQuick 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 sizePager size.
simplebooleanfalseSimple mode with an input instead of the page list.
showLessItemsbooleanfalseUse a smaller page window.
pagerCountnumber-Number of page buttons, an odd integer from 5 to 21; takes precedence over showLessItems. See page window.
responsivebooleanfalseWhen 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.
positionTablePaginationPosition[]bottom rightPager positions, ['bottomRight'] by default; top and bottom can both be used. ['none'] hides the pager but keeps pagination.
layoutTablePaginationLayoutpreset layoutOrdered array or { left, right }; see composable layouts.
localeobject-Pagination text overrides; fields are listed in the type declarations.
classstring-Class for the pagination area.
styleCSSProperties-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.

vue
<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 ​

Edit in Playground

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 layout is omitted, the total, page-size select, pager and jumper are arranged in that order.
  • When pagerCount is not specified, the native 7-page window is used, and showLessItems: true maps 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 Page after 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, a small table maps to compact pagination, and middle / large map 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 configSlotDescription
theme.paginationrootPagination root container.
theme.paginationlayoutTwo-region container of a custom pagination layout.
theme.paginationleftLeft region of the pagination layout.
theme.paginationrightRight region of the pagination layout.
theme.paginationextensionContainer for custom pagination content.
theme.paginationpagesContainer for page numbers and the previous / next navigation buttons.
theme.paginationitemPage number and navigation buttons.
theme.paginationactiveExtra styles for the current page number.
theme.paginationjumpButton that skips a group of page numbers.
theme.paginationjumpEllipsisEllipsis in the jump button.
theme.paginationjumpIconIcon shown when the jump button is hovered.
theme.paginationcontrolsArea for controls such as page size and quick jump.
theme.paginationsimpleControlsSimple mode controls area.
theme.paginationsimpleInputExtra styles for the page number input in simple mode.
theme.paginationslashSeparator between the current page and the total page count.
theme.paginationgoQuick jump confirm button.
theme.paginationinputPage number input.
theme.paginationselectPage size select button.
theme.paginationpopupPage size dropdown panel.
theme.paginationoptionPage size dropdown option.
theme.paginationoptionActiveExtra styles for the selected page size option.
theme.paginationtotalTotal count text.
theme.paginationiconPagination 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.

ts
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',
      },
    },
  },
})
ts
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 ​

VariablePurposeantdvelement-plus
--vtg-pagination-sizeButton height and minimum width at the default size32px32px
--vtg-pagination-size-smButton height and minimum width at the small size24px24px
--vtg-pagination-gapGap between the navigation, controls and custom layout regions8px16px
--vtg-pagination-marginVertical padding of the pagination container16px16px
--vtg-pagination-radiusRadius of buttons and inputs6px2px
--vtg-pagination-input-widthQuick jump input width50px56px
--vtg-pagination-borderDefault border color of page number buttonstransparenttransparent
--vtg-pagination-bgDefault background of page number buttonstransparentvar(--color-surface)
--vtg-pagination-active-bgCurrent page number backgroundvar(--color-surface)var(--color-surface)
--vtg-pagination-active-colorCurrent page number text colorvar(--color-primary)var(--color-primary)
--vtg-pagination-active-borderCurrent page number button border colorvar(--color-primary)transparent
--vtg-pagination-popup-zPage size dropdown panel z-index10502000
--vtg-pagination-popup-radiusPage size dropdown panel radiusvar(--vtg-table-popup-radius)var(--vtg-table-popup-radius)
--vtg-pagination-popup-shadowPage size dropdown panel shadowvar(--vtg-table-popup-shadow)var(--vtg-table-popup-shadow)
--vtg-pagination-font-sizeDefault pagination font sizenot read14px
--vtg-pagination-font-size-smSmall-size pagination font sizenot read12px
--vtg-pagination-page-gapGap between adjacent page numbersnot read0px
--vtg-pagination-control-gapGap between controls such as quick jumpnot read8px
--vtg-pagination-select-widthPage size selector widthnot read128px
--vtg-pagination-select-width-smPage size selector width at the small sizenot read100px
--vtg-table-popup-radiusRadius of table popups such as filtering and batch selection6px2px
--vtg-table-popup-borderTable popup border01px solid var(--vtg-border-color-lighter, var(--color-default))
--vtg-table-popup-padding-blockTable popup vertical padding4px5px
--vtg-table-popup-padding-inlineTable popup horizontal padding4px0px
--vtg-table-popup-shadowTable popup shadow0 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:

ts
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 carries extra.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, currentDataSource is the processed data before pagination; in remote scenarios it contains only loaded records. select keeps 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; preserveSelectedRowKeys retains uncontrolled keys across pages and caches selected records without requesting unloaded pages.
  • title / footer receive the displayed data of the current page. Dragging happens only within the current page but returns the complete input dataSource.
  • 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
ts
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
}
ts
export interface TablePaginationState {
  current: number
  pageSize: number
  total: number
}
ts
export type TablePaginationPosition =
  | 'topLeft'
  | 'topCenter'
  | 'topRight'
  | 'bottomLeft'
  | 'bottomCenter'
  | 'bottomRight'
  | 'none'
ts
export type PaginationItemType = 'page' | 'prev' | 'next' | 'jump-prev' | 'jump-next'
ts
export type TablePaginationBuiltinLayoutItem =
  | 'total'
  | 'sizes'
  | 'prev'
  | 'pager'
  | 'next'
  | 'jumper'
ts
export type TablePaginationLayoutItem = TablePaginationBuiltinLayoutItem | { readonly slot: string }
ts
export type TablePaginationLayout =
  | readonly TablePaginationLayoutItem[]
  | {
      readonly left?: readonly TablePaginationLayoutItem[]
      readonly right?: readonly TablePaginationLayoutItem[]
    }
ts
export type TablePaginationSlotProps = Readonly<
  TablePaginationState & {
    name: string
    pageCount: number
    range: readonly [number, number]
    disabled: boolean
    position: Exclude<TablePaginationPosition, 'none'>
    region: 'inline' | 'left' | 'right'
  }
>
ts
export type TableFiltersInfo = Record<string, (string | number | boolean)[] | null>
ts
export interface SorterResultLike<TRecord extends object = Record<string, any>> {
  column: ColumnType<TRecord> | undefined
  columnKey: Key | undefined
  order: SortOrder
  field: ColumnType<TRecord>['dataIndex']
}
ts
export type VTableSorterResult<TRecord extends object = Record<string, any>> =
  | SorterResultLike<TRecord>
  | Array<SorterResultLike<TRecord>>
ts
export interface TableChangeExtra<TRecord extends object = Record<string, any>> {
  action: 'sort' | 'filter' | 'select' | 'paginate'
  /** Available only when pagination is enabled. */
  pagination?: TablePaginationState
  currentDataSource: TRecord[]
}
ts
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
}
ts
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
}