API Reference
This page provides component behavior reference and a composable index: look up props, events, slots, defaults, controlled-mode rules, and function options, state and methods.
For the full relationships of TypeScript types such as TableColumnsType, Breakpoint and RowSelection, see the Type reference. The complete Type Declarations at the end of this page let you look up parameters and return values directly.
Import entry
We recommend importing components, constants and types from the single @vtable-guild/vtable-guild entry.
import {
VTable,
VTableToolbar,
VTableColumnSettings,
VTableSummary,
useTableRequest,
useTableQuery,
useTableEdit,
createTableRenderers,
EXPAND_COLUMN,
SELECTION_COLUMN,
type TableColumnsType,
type RowSelection,
type Expandable,
type TableInstance,
} from '@vtable-guild/vtable-guild'Composable index
Find a function by name below and open its complete API. Feature pages keep the usage examples, while their API sections collect options and return values. Import all these functions from @vtable-guild/vtable-guild.
| Function | Purpose | Complete API |
|---|---|---|
useTableQuery | Query drafts, param transforms, submission and reset. | Query submission |
useTableEdit | Row drafts, validation, saving, cancellation and controlled details. | Editing |
useTableEditable | Connect column editors to row drafts and host controls. | Column editors |
useTableRequest | Remote requests, pagination, loading and refresh. | Request management |
useTableDictionary | Options, search and loading for a shared dictionary. | Remote dictionaries |
useColumnState | Restore and save column visibility, pinning and order preferences. | Column state |
useColumns | Parse leaf columns and grouped header metadata. | Low-level column parsing |
useRowDragSort | Compose native row drag events and controlled reorder results. | Low-level row dragging |
useTheme | Compose theme and instance slot classes for custom components. | Low-level theming |
Toolbar and column settings
VTableToolbar is a standalone component; place it in VTable's #title slot to compose the two. It shares v-model:columns and v-model:size with the table. Reload, density and column settings are enabled by default; full screen is enabled with options.fullScreen and targets the surrounding table by default, and fullscreenTarget can point at another element. Reload only emits reload; the application manages data requests and loading.
#actions adds application buttons such as export or create; #settings replaces the built-in tools entirely; options: false turns off only the built-in tools and keeps the application slots. See Toolbar for the complete props, events, slots and a runnable export example.
Use VTableColumnSettings on its own when you only need density and column settings. It covers visibility, pinning to the left or right, and drag reordering of top-level columns within the same fixed region. options.density / setting / fixed / draggable toggle each entry; the column field disable locks actions, hideInSetting hides the item, and #columnLabel customizes labels. The panel's reset restores initial visibility only; useColumnState().reset() restores visibility, pinning and order. See Column display and order.
Query and editing protocols
These Vue composables follow the query state of Ant Design ProTable and the row state of EditableProTable. They do not generate a complete form from columns. Controls, form validation and data submission stay with the host UI library and application services, and antdv / element-plus share the same protocol.
| Entry | Purpose | Full API |
|---|---|---|
useTableQuery<TValues, TParams> | Query draft, parameter transforms, submit and reset. Input only changes the draft; submit() transforms it and then submits. | Query submission |
useTableEdit<TRecord> | Row editing drafts, validation, save and cancel. A failure keeps the draft; editing ends once the save completes. | Editing |
Connect a query to the request manager with onSubmit: request.submit and onReset: request.reset. Both submit and reset return to the first page, and reset also clears sorting and filters. useTableQuery never issues the first request itself and does not clear fields hidden by collapsing. Editing defaults to single-row mode, where starting a second row returns false; multi-row mode handles rows one by one. Returning false from onSave / onCancel keeps the row in editing, and a thrown error becomes a row error. Drafts do not depend on visible row components; the application updates the data source and explicitly cancels old drafts when switching data sets.
VTable Props
Data and structure
| Prop | Type | Default | Description |
|---|---|---|---|
dataSource | TRecord[] | [] | Table data source. |
pagination | false | TablePaginationConfig | false | Pass {} to enable local or remote pagination; see Pagination. |
columns | TableColumnsType<TRecord> | [] | Column configuration; supports leaf columns, column groups and column placeholder constants. |
columnOrder | Key[] | - | Column display order; see Column display and order. |
rowKey | string | ((record: TRecord) => Key) | 'key' | Unique row identity. Selection state is recorded by row key, so it must be stable and unique. |
childrenColumnName | string | 'children' | Field name of the child nodes in tree data. |
indentSize | number | 15 | Indent width of tree data, in px. |
loadData | TableTreeLoadData<TRecord> | - | (record, { signal }) => Promise<TRecord[]>; lazily loads nodes that provide no children. |
isLeaf | (record: TRecord) => boolean | - | Explicitly marks the leaf nodes of a lazy tree; a node that already has children: [] also counts as a leaf. |
onTreeLoadError | (error: Error, record: TRecord) => void | - | Lazy loading error notification; can be bound with @tree-load-error. |
renderers | TableFieldRenderers<TRecord> | Built-in mapping | Overrides or extends the read-only renderers for valueType per table. |
Lazy loading requires stable row keys. Concurrent requests for the same node are deduplicated, and a response that arrives after the node is collapsed goes into the cache without expanding it again. Removing a node, replacing a record that has the same key, or unmounting invalidates the old task, and loaded results are not written into the input data. Selection relationships only cover loaded descendants, and pagination still counts root nodes. See Tree table.
Server-side calculation and requests
| Prop | Type | Default | Description |
|---|---|---|---|
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. |
manual only decides which local computations to skip; omitted object fields are treated as false. It neither sends nor prevents network requests. Header state, filter controls and change(filters, sorter, extra) keep working. sorter: true on its own still means local default sorting, so enable manual.sort as well for server-side sorting.
The table can paginate a complete result set locally: pass all records and pagination: { defaultPageSize: 10 }, leave manual.pagination off, and do not connect paging events to a request function. For remote pagination, pass an explicit total and enable manual.pagination to skip local slicing and display the page returned by the server.
The optional useTableRequest provides requests, loading state and refresh methods. The standard fully remote setup binds its manual, pagination and onChange together. The returned manual is a fixed, frozen plain object { sort: true, filter: true, pagination: true }, not a ref; it is equivalent to :manual="true". onChange turns sorting, filtering and paging into requests. Overriding the component's manual does not change this request behavior, and the Hook currently has no per-operation request switches.
For local processing after loading the complete result set, use only the Hook's data, loading and refresh capabilities, with separate local pagination and column state. Mixed modes require application code to route requests by extra.action and keep sorting, filtering and pagination state in sync. See Choosing a processing mode for complete examples.
Visuals and layout
| Prop | Type | Default | Description |
|---|---|---|---|
size | 'small' | 'middle' | 'large' | 'large' for antdv, 'middle' for element-plus | Table size, aligned with ant-design-vue naming. |
loading | boolean | object | false | Loading state; for the object form, see options. |
bordered | boolean | false | Shows borders. |
striped | boolean | false | Enables striped rows. |
hoverable | boolean | true | Enables row hover highlight. |
tableLayout | 'auto' | 'fixed' | - | Table layout mode. |
showHeader | boolean | true | Whether to show the header. |
headerEllipsis | boolean | false | Also truncates the headers of columns that enable column.ellipsis to a single line with an ellipsis. |
class | string | - | Extra class on the root node. |
columnEmptyText | VNodeChild | false | false | Replaces null or undefined cell values; zero, false and empty strings are kept. |
loading
Options for the object form of loading.
| Field | Type | Default | Description |
|---|---|---|---|
spinning | boolean | true | Whether the table is loading. |
indicator | VNodeChild | Preset indicator | Custom loading indicator. |
tip | string | - | Hint text below the indicator. |
delay | number | 0 | Milliseconds to wait before showing; nothing is shown if loading ends during the delay. |
wrapperClassName | string | - | Class added to the table root element while loading. |
Scrolling and positioning
| Prop | Type | Default | Description |
|---|---|---|---|
scroll | object | - | Horizontal and vertical scrolling; see options. Providing y creates a scroll area with a fixed header. |
sticky | boolean | TableSticky | false | Sticky header and summary row; for the object form, see options. |
virtual | boolean | false | Enables virtual scrolling; scroll.y must be set as well. |
virtualColumn | boolean | false | Horizontal virtualization: renders only the columns inside the viewport; virtual must be enabled as well. It only pays off with many columns; see Virtual scrolling. |
rowHeight | number | - | Fixed row height (px), effective only with virtual. Declaring it skips all row height measurement, so the visible range is always computed in O(1). Pass it only when every row really has this height; see Virtual scrolling. |
getPopupContainer | (triggerNode: HTMLElement) => HTMLElement | - | Mount container for the filter, selection and page-size menus. |
scroll
| Field | Type | Default | Description |
|---|---|---|---|
x | number | string | - | Content width of the horizontal scroll area; numbers are treated as px. Horizontal scrolling appears when it exceeds the container width. |
y | number | string | - | Maximum height of the body; when provided, the header is fixed. 'auto' fills the remaining height of the parent container, which must have a definite height; see Virtual scrolling. |
scrollToFirstRowOnChange | boolean | true when pagination is enabled | Scrolls vertically back to the first row after sorting, filtering or paginating. |
sticky
Options for the object form of sticky; true equals {}.
| Field | Type | Default | Description |
|---|---|---|---|
offsetHeader | number | 0 | Distance between the sticky header and the top of the scroll container, in px. |
offsetSummary | number | 0 | Distance between the bottom-fixed summary row and the bottom of the container, in px. |
offsetScroll | number | - | Reserved in the type; not used in the current version. |
getContainer | () => Window | HTMLElement | - | Reserved in the type; not used in the current version. |
Themes and locales
| Prop | Type | Default | Description |
|---|---|---|---|
ui | SlotProps<{ slots: Record<TableSlots, string> }> | - | Theme slot class overrides for this table instance. For the full slot list, see the ui slot reference. |
locale | LocaleName | Global config or 'zh-CN' | Locale identifier used by this table instance. |
locales | LocaleRegistry | {} | Extra locale packs registered on this instance. |
localeOverrides | DeepPartial<VTableGuildTableLocale> | {} | Partial locale overrides for this instance. |
Interactive capabilities
| Prop | Type | Default | Description |
|---|---|---|---|
rowSelection | RowSelection<TRecord> | - | Enables the row selection column; for its fields, see Row selection · RowSelection. |
expandable | Expandable<TRecord> | - | Enables expandable rows. |
rowDraggable | boolean | false | Enables row drag sorting; see Row drag sorting. |
expandedRowKeys | Key[] | - | Controlled list of expanded keys for tree data. |
defaultExpandedRowKeys | Key[] | - | Default list of expanded keys for tree data. |
defaultExpandAllRows | boolean | false | Expands all nodes of tree data by default. |
onExpand | (expanded: boolean, record: TRecord) => void | - | Expand/collapse callback for tree data. |
onExpandedRowsChange | (expandedKeys: Key[]) => void | - | Callback when the expanded keys of tree data change. |
transformCellText | TransformCellText<TRecord> | - | Transforms cell text in one place; opt contains text, column, record and index. |
showSorterTooltip | boolean | TableTooltipConfig | true for antdv, false for element-plus | Table-level sorter tooltip config; a column-level showSorterTooltip overrides it. |
sortDirections | SortOrder[] | ['ascend', 'descend'] | Table-level list of sort directions, used as the default for column-level sortDirections. |
Custom structure
| Prop | Type | Default | Description |
|---|---|---|---|
rowClassName | string | RowClassName<TRecord> | - | Adds a class to body rows. |
customRow | GetComponentProps<TRecord> | - | Injects attributes, events and styles into body rows. |
customHeaderRow | (columns: (ColumnType<TRecord> | ColumnGroupType<TRecord>)[], index?: number) => CellAdditionalProps | - | Injects attributes, events and styles into header rows. |
title | (data: TRecord[]) => VNodeChild | - | Render function for the table title area. |
footer | (data: TRecord[]) => VNodeChild | - | Render function for the table footer area. |
Cell display enhancements
| Field | Type | Default | Description |
|---|---|---|---|
copyable | boolean | object | - | Enables the copy button; for the object form, see options. |
tooltip | string | TableTooltipConfig | - | Header help text; for the object form, see options. |
valueEnum | ColumnValueEnum | - | Maps raw values to display text and status. Accepts an object or a Map. |
valueType | string | - | Specifies a built-in field render type or a registered custom type. |
fieldProps | TableFieldProps | ((context: CustomRenderContext<TRecord>) => TableFieldProps) | - | Configures the field renderer. Accepts an object or a function that returns the configuration from the cell context. |
See Cell display and enums for the object forms of copyable and tooltip; table-level and column-level showSorterTooltip use the same TableTooltipConfig.
Column-level valueEnum?: ColumnValueEnum accepts an object or a Map whose values are text or { text, status }; status can be success, warning, error, processing or default. filters: true builds filter items from the enum. filters: false provides no default filter items. onFilter: false skips local filtering, and onFilter: true uses equality matching. See Cell display and enums.
Column-level valueType?: string selects text / digit / money / date / dateTime / time / dateRange / dateTimeRange / percent / progress / tag or a custom type; fieldProps is an options object or a callback that receives the cell context. createTableRenderers<TRecord>(overrides) merges the built-in and application maps and returns an immutable registry, which you pass through the table's renderers without modifying any global registry. Numbers, money and percentages use Intl, and dates can opt into Intl through dateFormat; tag / progress share the status theme with valueEnum.
transformCellText runs first, and the field renderer consumes the transformed value and the enum label. customRender and valid bodyCell content take precedence, empty values use the existing columnEmptyText, and unknown types fall back to the enum or the raw value. The data contracts for sorting, filtering and default copying stay unchanged. Renderers only provide read-only display. See Field renderers.
Remote dictionaries
createTableDictionary({ key, request, cacheTime?, maxEntries? }) creates an instance-isolated cache; useTableDictionary({ dictionary, params?, selectedOptions?, debounceTime? }) turns the shared result into options for host controls, column valueEnum and filters for the complete dictionary. It returns search / reload / cancel plus loading/error state; partial search results do not generate header filters automatically. See Remote dictionaries for the full protocol.
Schema query and column editors
VTableQuery takes useTableQuery state, a host control registry, and either fields or columns. It renders the responsive QueryFilter by default. Set layoutType="LightFilter" for popup-based filters. Use validate for host form validation and rootTag="div" inside an existing form. See Schema query.
useTableEditable takes columns, controls and row-editing options, and connects the conditions, transforms, rules and dictionaries of column.editor to the same row draft. Templates bridge through VTableEditCell, and TSX can call renderEditor; when there is no editor content, the read-only fallback is kept. Entering edit mode keeps column widths and row heights by default (layout: 'stable'), and errorPlacement: 'tooltip' keeps validation errors from stretching the row; VTableEditShell gives hand-written controls the same layout. See Column editors.
The controlled dataSource/onChange, records, getOriginal/getDrafts/getValues/validateAll/reset, createRecord/maxRows and the position/cache strategy of add in useTableEdit / useTableEditable serve detail tables inside a main form. validateAll returns the submission snapshot from the same validation pass, including off-screen records held by the client, and does not call save; onChange does not fire on every keystroke. See Detail forms.
VTable instance methods
Type the template ref with the public TableInstance. Regular and virtual bodies share the same interface. See Table instance.
| Method | Type | Description |
|---|---|---|
scrollTo | (options: TableScrollToOptions) => Promise<boolean> | Scrolls to the given row or position; see options. Returns false when the target is not found, the table is not mounted or the arguments are invalid. |
retryTreeLoad | (key: Key) => Promise<boolean> | Retries lazy loading for the node without changing its expanded state. |
getTreeLoadError | (key: Key) => Error | undefined | Reads the lazy loading error of the row. |
Positioning only covers loaded, visible records on the current page. Records on other pages, inside collapsed tree nodes or removed by filters return false; change the page, load or expand first, then position. Virtual lists with variable row heights rely on the existing measurement and correction, so the Promise means the positioning has been committed and does not guarantee the final pixel position after images load later.
Column behavior
Basic fields
| Field | Type | Default | Description |
|---|---|---|---|
key | Key | - | Unique column identity; passing it explicitly is recommended. |
title | ColumnTitle<TRecord> | - | Column title; can be text, a VNode or a render function. |
dataIndex | DataIndex | - | Data field path, such as 'name' or ['address', 'city']. |
width | number | string | - | Column width; numbers are treated as px. |
align | AlignType | - | Alignment of the column content. |
ellipsis | boolean | { showTitle?: boolean } | false | Truncates overflowing cell content with an ellipsis; with showTitle: false, the hover tooltip is not shown. |
className | string | - | Extra class for the cells of the column. |
colSpan | number | - | Number of columns the header cell spans. |
visible | boolean | true | Controls whether the column is shown; see Column display and order. |
responsive | Breakpoint[] | - | Shows the column when the current screen matches any of the breakpoints. |
Custom rendering
| Field | Type | Default | Description |
|---|---|---|---|
customRender | (ctx: CustomRenderContext<TRecord>) => VNodeChild | RenderedCell | - | Custom body cell content. Returning a RenderedCell sets both the content and the cell attributes. |
customCell | GetComponentProps<TRecord, TRecord> | - | Injects attributes, events and styles into body cells. |
customHeaderCell | GetComponentProps<ColumnType<TRecord> | ColumnGroupType<TRecord>, TRecord> | - | Injects attributes, events and styles into header cells. |
import type { TableColumnType } from '@vtable-guild/vtable-guild'
interface NameRow {
key: number
name: string
}
const nameColumn: TableColumnType<NameRow> = {
key: 'name',
dataIndex: 'name',
customRender: ({ text, index }) =>
index === 0
? { children: String(text), props: { colSpan: 2, style: { fontWeight: 'bold' } } }
: String(text),
}Fixed columns and column resizing
| Field | Type | Default | Description |
|---|---|---|---|
fixed | 'left' | 'right' | true | - | Fixed column position; true is equivalent to 'left'. |
resizable | boolean | false | Whether the column width can be adjusted by dragging. |
minWidth | number | - | Lower bound of a leaf column in auto/fixed layouts and while dragging (a finite, non-negative CSS px value); when unset, only dragging applies a 50px lower bound. |
maxWidth | number | - | Limits the drag target only; when it is smaller than minWidth, the lower bound wins. |
width is a target width and cannot override a valid minWidth. When the minimums add up to more than the container, the table scrolls horizontally, whether or not the columns are resizable. See Minimum column width and layout.
Sorting
| Field | Type | Default | Description |
|---|---|---|---|
sorter | ColumnSorter<TRecord> | - | Enables sorting; supports the default comparison, a custom compare function and a multi-column sort object. |
sortOrder | SortOrder | - | Controlled sort direction. |
defaultSortOrder | SortOrder | - | Sort direction an uncontrolled column is initialized with. |
sortDirections | SortOrder[] | Inherits the table-level setting | Sort directions available for this column. An empty array falls back to ['ascend', 'descend']. |
showSorterTooltip | boolean | TableTooltipConfig | Inherits the table-level setting | Column-level sorter tooltip switch and config. |
Table-level sortDirections and showSorterTooltip act as defaults; column-level config takes precedence.
Filtering
| Field | Type | Default | Description |
|---|---|---|---|
filters | ColumnFilterItem[] | boolean | - | true generates the options from valueEnum, false provides no options; you can also pass a custom array. |
onFilter | boolean | ((value: string | number | boolean, record: TRecord) => boolean) | - | true uses the default matching rule, a function defines a custom one, and false skips local filtering. |
filterMultiple | boolean | true | Whether multiple filter values can be selected. |
filteredValue | Array<string | number | boolean> | null | - | Controlled filter values; null and [] both mean controlled with no filter value. |
defaultFilteredValue | Array<string | number | boolean> | - | Uncontrolled default filter values. |
customFilterDropdown | boolean | false | Uses the table-level customFilterDropdown slot. |
filterSearch | boolean | ((input: string, filter: ColumnFilterItem) => boolean) | false | Search within the filter items. |
filterMode | 'menu' | 'tree' | 'menu' | Display mode of the filter items. |
filterResetToDefaultFilteredValue | boolean | false | Restores the default filter values on reset. |
filterDropdownOpen | boolean | - | Controlled visibility of the filter dropdown. |
onFilterDropdownOpenChange | (visible: boolean) => void | - | Callback when the visibility of the filter dropdown changes. |
filtered | boolean | - | Controls the highlight state of the filter icon externally; does not change the filtering logic. |
filterIcon | (opt: { filtered: boolean }) => VNodeChild | - | Custom filter icon. |
filterDropdown | VNodeChild | ((props: CustomFilterDropdownSlotProps<TRecord>) => VNodeChild) | - | Column-level custom filter panel; takes precedence over the table-level slot. |
Column settings
| Field | Type | Default | Description |
|---|---|---|---|
hideInSetting | boolean | false | Hides the column in the column settings panel. |
disable | boolean | { checkbox?: boolean; fixed?: boolean; order?: boolean } | - | Locks column settings actions. Visibility, fixing and ordering can be restricted separately. |
Column editors
| Field | Type | Default | Description |
|---|---|---|---|
editor | false | TableColumnEditor<TRecord> | - | Configures the column editor. Read by useTableEditable to connect host controls and row drafts. |
Grouped headers
| Field | Type | Default | Description |
|---|---|---|---|
children | Array<ColumnType<TRecord> | ColumnGroupType<TRecord>> | - | Child column configuration. A column that has children acts as a column group. |
Column groups do not receive leaf-column behaviors such as sorting, filtering, dataIndex and customRender.
Row Selection
rowSelection enables the selection column, with support for multiple selection, single selection, linked selection in tree data, batch-selection menus and controlled selection state.
| Field | Type | Default | Description |
|---|---|---|---|
type | 'checkbox' | 'radio' | 'checkbox' | Selection type. |
selectedRowKeys | Key[] | - | Controlled selected keys, owned by application code; data source changes never automatically prune them, regardless of preserve. |
defaultSelectedRowKeys | Key[] | - | Default selected keys. |
onChange | (selectedRowKeys: Key[], selectedRows: TRecord[]) => void | - | Selection change callback; rows follows key order, skipping unavailable records. Without preserve, records come only from the current data source; with preserve, they also include previously cached selected records from other pages. |
onSelect | (record: TRecord, selected: boolean, selectedRows: TRecord[]) => void | - | Single-row selection change callback; selectedRows matches the selection result of onChange for the same action. |
onSelectMultiple | (selected: boolean, selectedRows: TRecord[], changeRows: TRecord[]) => void | - | Shift multi-selection callback; selectedRows matches onChange for the same action, while changeRows keeps the action traversal order. |
onSelectAll | (selected: boolean, selectedRows: TRecord[], changeRows: TRecord[]) => void | - | Select-all change callback; selectedRows matches onChange for the same action, while changeRows keeps the action traversal order. |
onSelectInvert | (selectedRowKeys: Key[]) => void | - | Callback when the selection is inverted. |
onSelectNone | () => void | - | Callback when the selection is cleared. |
getCheckboxProps | (record: TRecord) => { disabled?: boolean; name?: string } | - | Injects attributes into the selection control. |
columnWidth | number | string | 48 | Width of the selection column. |
fixed | boolean | 'left' | 'right' | - | Fixed position of the selection column. |
columnTitle | string | VNodeChild | - | Header content of the selection column. |
renderCell | (value: boolean, record: TRecord, index: number, originNode: VNodeChild) => VNodeChild | RenderedCell | - | Custom selection cell. |
checkStrictly | boolean | true | Whether parent and child rows are selected independently in tree data. |
selections | boolean | (SelectionItem | SelectionSentinel)[] | false | Default or custom batch selection menu; for the default menu constants, see SelectionSentinel. |
hideSelectAll | boolean | false | Hides the select-all checkbox and the selection dropdown. |
preserveSelectedRowKeys | boolean | false | Retains uncontrolled selected keys when the data source changes and caches loaded selected records for cross-page callbacks; controlled keys remain owned by application code, and unloaded pages are never requested automatically. |
For the default batch-selection constants, see SelectionSentinel.
With pagination enabled, the header select-all checkbox and invert selection are limited to the current page. The "Select all data" menu (selections: true or [SELECTION_ALL]) selects all loaded, selectable records after filtering. Controlled selectedRowKeys are owned by application code and are not automatically pruned when the data source changes; uncontrolled mode prunes absent keys when preserve is not enabled. preserveSelectedRowKeys: true also caches selected records across pages so callbacks can return records from earlier pages; unloaded pages are never requested automatically. See Pagination and cross-page selection.
Selection callbacks return rows in key order, skipping keys whose records are unavailable. For the same action, onChange and the single-row, select-all or Shift multi-selection callback share the normalized selection result. See Callback order for ordering and missing-record rules.
Expandable
expandable configures expandable row content. The expand props for tree data are configured at the top level of VTable.
| Field | Type | Default | Description |
|---|---|---|---|
expandedRowRender | (record: TRecord, index: number, indent: number, expanded: boolean) => VNodeChild | - | Render function for the expanded row content. |
expandedRowKeys | Key[] | - | Controlled expanded row keys. |
defaultExpandedRowKeys | Key[] | - | Default expanded row keys. |
expandRowByClick | boolean | false | Expands a row when the whole row is clicked. |
expandIcon | (props: { expanded: boolean; record: TRecord; expandable: boolean; onExpand: (record: TRecord, e: Event) => void }) => VNodeChild | - | Custom expand icon. |
onExpand | (expanded: boolean, record: TRecord) => void | - | Expand/collapse callback. |
onExpandedRowsChange | (expandedKeys: Key[]) => void | - | Callback when the expanded keys change. |
columnWidth | number | string | - | Width of the expand column. |
fixed | 'left' | 'right' | true | - | Fixed position of the expand column; true is equivalent to 'left'. |
defaultExpandAllRows | boolean | false | Expands all rows by default. |
rowExpandable | (record: TRecord) => boolean | - | Determines whether a row can be expanded. |
showExpandColumn | boolean | true | Whether to show the expand column. |
expandIconColumnIndex | number | 0 | Zero-based position of the expand column among the application columns. An explicit EXPAND_COLUMN placeholder takes precedence. |
columnTitle | string | number | '' | Title of the expand column; can be overridden by #expandColumnTitle. |
expandedRowClassName | string | RowClassName<TRecord> | - | Class of the expanded row. |
Events
TRecord is your application's row type. VTableEventProps<TRecord> provides types for template event handlers and event props. If you only need pagination, use pagination.onChange(page, pageSize); in the table event, read the pagination state from extra.pagination.
| 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'. |
resizeColumn | (column: ColumnType<TRecord>, width: number) => void | Fires after a column width drag ends. |
rowDragEnd | (newData: TRecord[], info: RowDragSortInfo) => void | Fires when row drag sorting ends and the order has changed; see Row drag sorting. |
change keeps its three-argument signature. With pagination enabled it adds extra.pagination; extra.action supports 'sort', 'filter', 'select' and 'paginate'.
For sort, filter and paginate events, extra.currentDataSource is the processed data before pagination; for selection events it is the data displayed on the current page. With remote data it only contains loaded records.
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
}Slots
| Slot | Payload type | Description |
|---|---|---|
bodyCell | TableBodyCellSlotProps<TRecord> | Custom cell content. |
headerCell | TableHeaderCellSlotProps<TRecord> | Custom header cell content. |
empty | () | Custom empty state. |
loading | () | Custom loading state. |
customFilterDropdown | CustomFilterDropdownSlotProps<TRecord> | Table-level custom filter panel; the column must set customFilterDropdown: true. |
customFilterIcon | { column: ColumnType<TRecord>; filtered: boolean } | Table-level custom filter icon. |
title | TableDataSlotProps<TRecord> | Custom title area. |
footer | TableDataSlotProps<TRecord> | Custom footer area. |
summary | () | Custom summary area. |
expandColumnTitle | () | Custom expand column title. |
paginationItem | TablePaginationSlotProps | Renders application content for the pagination at { slot: 'name' } in pagination.layout. |
These are Vue slots. To override structural styles through classes, see the ui slot reference.
VTableSummary
VTableSummary renders summary rows.
| Component | Description |
|---|---|
VTableSummary | Summary container, placed inside the table's #summary slot. |
VTableSummary.Row | Summary row; it has no props. |
VTableSummary.Cell | Summary cell. |
VTableSummary Props
| Prop | Type | Default | Description |
|---|---|---|---|
fixed | boolean | 'top' | 'bottom' | false | Fixes the summary row; true is equivalent to 'bottom'. |
VTableSummary.Cell Props
| Prop | Type | Default | Description |
|---|---|---|---|
index | number | Required | Zero-based index of the column the cell is in. |
colSpan | number | - | Number of columns to span. |
rowSpan | number | - | Number of rows to span. |
align | AlignType | - | Content alignment. |
Low-level composables
These functions support custom headers, draggable rows and themed components. When using VTable column definitions, rowDraggable and theme configuration, the component handles the corresponding wiring.
useColumns
useColumns<TRecord extends Record<string, unknown>>(columns) accepts a column getter and returns parsing results that react to column changes. Apply visibility, responsive filtering and ordering in the supplied getter first.
| Parameter | Type | Description |
|---|---|---|
columns | () => TableColumnsType<TRecord> | Reactive column getter supporting groups; selection and expand column sentinels are excluded from the parsed result. |
| Property | Type | Description |
|---|---|---|
leafColumns | ComputedRef<TableColumnType<TRecord>[]> | Leaf columns recursively flattened from groups. |
headerRows | ComputedRef<HeaderCellMeta<TRecord>[][]> | Grouped headers arranged by depth; HeaderCellMeta describes the inferred structure below and needs no separate import. |
Each header in headerRows has the structure below. HeaderCellMeta describes the inferred function return structure; read its fields as shown in the table.
| Field | Type | Description |
|---|---|---|
column | TableColumnType<TRecord> | TableColumnGroupType<TRecord> | Column or group represented by the header. |
colSpan | number | Number of grid columns occupied by the header. |
rowSpan | number | Number of header rows spanned. |
colStart | number | Zero-based starting grid column. |
colEnd | number | Ending grid column. |
depth | number | Zero-based header depth. |
isLeaf | boolean | True when the header has no child columns. |
leafColumns | TableColumnType<TRecord>[] | Leaf columns associated with this header. |
leafIndex | number | Index in the full leafColumns returned by useColumns, or -1 for a group; distinct from the grid column. |
useRowDragSort
useRowDragSort<TRecord extends Record<string, unknown>>(options) computes a new row order through native HTML5 dragging. Bind the result of getBindings(record, index) to a tr, then write data back in onDrop. Tree nodes move before or after the target row and retain their subtrees.
| Option | Type | Default | Description |
|---|---|---|---|
enabled | () => boolean | Required | Dynamically enable row dragging. |
getRowKey | (record: TRecord, index: number) => Key | Required | Resolve a stable row key; index is only context for the resolver. |
dataSource | () => TRecord[] | Required | Return the current controlled data source. |
childrenColumnName | () => string | undefined | 'children' | Return the child field name for tree data. |
onDrop | (newData: TRecord[], info: RowDragSortInfo) => void | - | Called when a valid drop changes the order; the application writes newData back. |
| Property or method | Type | Description |
|---|---|---|
draggingKey | Ref<Key | null> | Key of the dragged row, or null while idle. |
dropTarget | Ref<RowDragDropTarget | null> | Drop target with a key and before/after position. |
isDragging | ComputedRef<boolean> | Whether a drag is in progress. |
getBindings | (record: TRecord, index: number, userProps?: Record<string, unknown>) => RowDragBindings | Create tr drag bindings; user handlers run after internal handlers. userProps.draggable=false opts that row out of dragging. |
RowDragDropTarget is { key: Key, position: 'before' | 'after' }. RowDragBindings contains the native attributes and events below; disabled rows still forward user handlers. For the table's built-in dragging, see Row drag sorting.
| Field | Type | Description |
|---|---|---|
draggable | boolean | Native draggable attribute. |
onDragstart | (event: DragEvent) => void | Begin a drag and update draggingKey. |
onDragover | (event: DragEvent) => void | Update the drop target. |
onDragleave | (event: DragEvent) => void | Clear target state when leaving a target. |
onDrop | (event: DragEvent) => void | Compute the reorder result and invoke the configured onDrop. |
onDragend | (event: DragEvent) => void | Clear drag state. |
useTheme
Call useTheme<T extends ThemeConfig>(componentName, defaultTheme, props, options?) in a custom component's setup. It combines classes in the order default theme, global theme[componentName], then instance ui, and its returned slot functions read the current reactive state.
| Parameter | Type | Description |
|---|---|---|
componentName | string | Component name in the global theme mapping. |
defaultTheme | MaybeRef<T> | Default theme object or ref; T extends ThemeConfig. |
props | Record<string, unknown> | Reactive component props, providing variants, ui and class. |
options | UseThemeOptions | undefined | Optional compatibility class configuration. |
| Option | Type | Description |
|---|---|---|
compatClasses | CompatClassConfig | undefined | Compatibility slots / variants class mapping, used only when global compatClass is enabled. |
| Property | Type | Description |
|---|---|---|
slots | Record<keyof T['slots'] & string, () => string> | A plain object of stable functions that lazily read the current default theme, global overrides and instance ui. Call slots.root() etc. for classes; root also merges props.class. |
CompatClassConfig has optional slots?: Record<string, string> and variants?: Record<string, Record<string, Record<string, string>>> fields. Slot keys come from the default theme at creation; a defaultTheme ref can update configuration for existing keys. See Theme overrides for global and instance configuration.
Related pages
Pagination
pagination?: false | TablePaginationConfig is disabled by default; pass {} to enable it. See the pagination configuration reference for the options; scroll.scrollToFirstRowOnChange controls whether changing pages scrolls back to the first row.
Type Declarations
Import all types from @vtable-guild/vtable-guild. For base types and the relationships between types, see the Type reference. The summary component props below are helper types used to document the declarations, not names exported by the package.
Props and column configuration
export interface TableProps<TRecord extends object = Record<string, any>> {
pagination?: false | TablePaginationConfig
manual?: boolean | TableManualConfig
columnEmptyText?: VNodeChild | false
renderers?: TableFieldRenderers<TRecord>
loadData?: TableTreeLoadData<TRecord>
isLeaf?: (record: TRecord) => boolean
onTreeLoadError?: (error: Error, record: TRecord) => void
dataSource: TRecord[]
columns: ColumnsType<TRecord>
columnOrder?: Key[]
rowKey?: string | ((record: TRecord) => Key)
loading?:
| boolean
| {
spinning?: boolean
indicator?: VNodeChild
tip?: string
delay?: number
wrapperClassName?: string
}
size?: 'small' | 'middle' | 'large'
bordered?: boolean
striped?: boolean
hoverable?: boolean
rowDraggable?: boolean
ui?: SlotProps<{ slots: Record<TableSlots, string> }>
class?: string
tableLayout?: TableLayout
showHeader?: boolean
headerEllipsis?: boolean
rowClassName?: string | RowClassName<TRecord>
customRow?: GetComponentProps<TRecord>
customHeaderRow?: (
columns: Array<ColumnType<TRecord> | ColumnGroupType<TRecord>>,
index?: number,
) => CellAdditionalProps
showSorterTooltip?: boolean | TableTooltipConfig
sortDirections?: SortOrder[]
locale?: LocaleName
locales?: LocaleRegistry
localeOverrides?: DeepPartial<VTableGuildTableLocale>
sticky?: boolean | TableSticky
getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement
transformCellText?: TransformCellText<TRecord>
rowSelection?: RowSelection<TRecord>
expandable?: Expandable<TRecord>
title?: (data: TRecord[]) => VNodeChild
footer?: (data: TRecord[]) => VNodeChild
scroll?: { x?: number | string; y?: number | string; scrollToFirstRowOnChange?: boolean }
virtual?: boolean
rowHeight?: number
virtualColumn?: boolean
childrenColumnName?: string
indentSize?: number
expandedRowKeys?: Key[]
defaultExpandedRowKeys?: Key[]
defaultExpandAllRows?: boolean
onExpand?: (expanded: boolean, record: TRecord) => void
onExpandedRowsChange?: (expandedKeys: Key[]) => void
}export interface ColumnType<TRecord extends object = Record<string, any>> {
key?: Key
title?: ColumnTitle<TRecord>
tooltip?: string | TableTooltipConfig
copyable?: ColumnCopyable<TRecord>
valueEnum?: ColumnValueEnum
valueType?: string
editor?: false | TableColumnEditor<TRecord>
fieldProps?: TableFieldProps | ((context: CustomRenderContext<TRecord>) => TableFieldProps)
hideInSetting?: boolean
disable?: boolean | { checkbox?: boolean; fixed?: boolean; order?: boolean }
dataIndex?: DataIndex
width?: number | string
align?: AlignType
ellipsis?: boolean | { showTitle?: boolean }
className?: string
colSpan?: number
customRender?: (ctx: CustomRenderContext<TRecord>) => VNodeChild | RenderedCell
customCell?: GetComponentProps<TRecord, TRecord>
customHeaderCell?: GetComponentProps<ColumnType<TRecord> | ColumnGroupType<TRecord>, TRecord>
fixed?: 'left' | 'right' | true
resizable?: boolean
minWidth?: number
maxWidth?: number
sorter?: ColumnSorter<TRecord>
sortOrder?: SortOrder
defaultSortOrder?: SortOrder
sortDirections?: SortOrder[]
filters?: ColumnFilterItem[] | boolean
onFilter?: boolean | ((value: string | number | boolean, record: TRecord) => boolean)
filterMultiple?: boolean
filteredValue?: (string | number | boolean)[] | null
defaultFilteredValue?: (string | number | boolean)[]
customFilterDropdown?: boolean
filterSearch?: boolean | ((input: string, filter: ColumnFilterItem) => boolean)
filterMode?: 'menu' | 'tree'
filterResetToDefaultFilteredValue?: boolean
filterDropdownOpen?: boolean
onFilterDropdownOpenChange?: (visible: boolean) => void
filtered?: boolean
filterIcon?: (opt: { filtered: boolean }) => VNodeChild
filterDropdown?: VNodeChild | ((props: CustomFilterDropdownSlotProps<TRecord>) => VNodeChild)
showSorterTooltip?: boolean | TableTooltipConfig
visible?: boolean
responsive?: Breakpoint[]
}export interface ColumnGroupType<TRecord extends object = Record<string, any>> extends Omit<
ColumnType<TRecord>,
| 'dataIndex'
| 'valueType'
| 'fieldProps'
| 'customRender'
| 'sorter'
| 'sortOrder'
| 'defaultSortOrder'
| 'sortDirections'
| 'filters'
| 'onFilter'
| 'filterMultiple'
| 'filteredValue'
| 'defaultFilteredValue'
| 'customFilterDropdown'
| 'filterSearch'
| 'filterMode'
| 'filterResetToDefaultFilteredValue'
| 'filterDropdownOpen'
| 'onFilterDropdownOpenChange'
| 'filtered'
| 'filterIcon'
| 'filterDropdown'
> {
children: Array<ColumnType<TRecord> | ColumnGroupType<TRecord>>
}export type ColumnsType<TRecord extends object = Record<string, any>> = Array<
ColumnType<TRecord> | ColumnGroupType<TRecord> | ColumnSentinel
>export interface ColumnTitleProps<TRecord extends object = Record<string, any>> {
sortOrder?: SortOrder
sortColumn?: ColumnType<TRecord>
sortColumns?: Array<{ column: ColumnType<TRecord>; order: SortOrder }>
filters?: Record<string, (string | number | boolean)[] | null>
}export type ColumnTitle<TRecord extends object = Record<string, any>> =
| VNodeChild
| ((props: ColumnTitleProps<TRecord>) => VNodeChild)export type GetComponentProps<TData, TRecord extends object = Record<string, any>> = (
data: TData,
index: number,
column?: ColumnType<TRecord>,
) => CellAdditionalProps | undefinedexport interface CustomRenderContext<TRecord extends object = Record<string, any>> {
text: unknown
value: unknown
record: TRecord
index: number
renderIndex: number
column: ColumnType<TRecord>
}export interface RenderedCell {
props?: CellAdditionalProps
children?: VNodeChild
}export interface CellAdditionalProps {
class?: string
className?: string
style?: CSSProperties
colSpan?: number
rowSpan?: number
colspan?: number
rowspan?: number
onClick?: (event: MouseEvent) => void
onMouseenter?: (event: MouseEvent) => void
onMouseleave?: (event: MouseEvent) => void
[key: string]: unknown
}export type RowClassName<TRecord = Record<string, any>> = (
record: TRecord,
index: number,
indent: number,
) => stringexport type TransformCellText<TRecord extends object = Record<string, any>> = (opt: {
text: unknown
column: ColumnType<TRecord>
record: TRecord
index: number
}) => unknownexport interface TableSticky {
offsetHeader?: number
offsetSummary?: number
offsetScroll?: number
getContainer?: () => Window | HTMLElement
}Selection and expansion
export interface RowSelection<TRecord extends object = Record<string, any>> {
preserveSelectedRowKeys?: boolean
type?: RowSelectionType
selectedRowKeys?: Key[]
defaultSelectedRowKeys?: Key[]
onChange?: (selectedRowKeys: Key[], selectedRows: TRecord[]) => void
onSelect?: (record: TRecord, selected: boolean, selectedRows: TRecord[]) => void
onSelectMultiple?: (selected: boolean, selectedRows: TRecord[], changeRows: TRecord[]) => void
onSelectAll?: (selected: boolean, selectedRows: TRecord[], changeRows: TRecord[]) => void
onSelectInvert?: (selectedRowKeys: Key[]) => void
onSelectNone?: () => void
getCheckboxProps?: (record: TRecord) => { disabled?: boolean; name?: string }
columnWidth?: number | string
fixed?: boolean | 'left' | 'right'
columnTitle?: string | VNodeChild
renderCell?: (
value: boolean,
record: TRecord,
index: number,
originNode: VNodeChild,
) => VNodeChild | RenderedCell
checkStrictly?: boolean
selections?: boolean | (SelectionItem | SelectionSentinel)[]
hideSelectAll?: boolean
}export interface SelectionItem {
key: string
text: string | VNodeChild
onSelect?: (changeableRowKeys: Key[]) => void
}export interface Expandable<TRecord extends object = Record<string, any>> {
expandedRowRender?: (
record: TRecord,
index: number,
indent: number,
expanded: boolean,
) => VNodeChild
expandedRowKeys?: Key[]
defaultExpandedRowKeys?: Key[]
expandRowByClick?: boolean
expandIcon?: (props: {
expanded: boolean
record: TRecord
expandable: boolean
onExpand: (record: TRecord, e: Event) => void
}) => VNodeChild
onExpand?: (expanded: boolean, record: TRecord) => void
onExpandedRowsChange?: (expandedKeys: Key[]) => void
columnWidth?: number | string
fixed?: 'left' | 'right' | true
defaultExpandAllRows?: boolean
rowExpandable?: (record: TRecord) => boolean
showExpandColumn?: boolean
expandIconColumnIndex?: number
columnTitle?: string | number
expandedRowClassName?: string | RowClassName<TRecord>
}Events and slots
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 RowDragSortInfo {
draggedKey: Key
targetKey: Key
orderedKeys: Key[]
}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 TableBodyCellSlotProps<TRecord extends object = Record<string, any>> {
text: unknown
record: TRecord
index: number
column: ColumnType<TRecord>
}export interface TableHeaderCellSlotProps<TRecord extends object = Record<string, any>> {
title: VNodeChild | undefined
column: ColumnType<TRecord> | ColumnGroupType<TRecord>
index: number
}export interface CustomFilterDropdownSlotProps<TRecord extends object = Record<string, any>> {
column: ColumnType<TRecord>
selectedKeys: (string | number | boolean)[]
setSelectedKeys: (keys: (string | number | boolean)[]) => void
confirm: (options?: { closeDropdown?: boolean }) => void
clearFilters: (options?: { confirm?: boolean; closeDropdown?: boolean }) => void
filters: ColumnFilterItem[]
visible: boolean
close: () => void
}export interface TableDataSlotProps<TRecord extends object = Record<string, any>> {
data: TRecord[]
}export interface TableSlotsDecl<TRecord extends object = Record<string, any>> {
bodyCell?: (props: TableBodyCellSlotProps<TRecord>) => VNodeChild
headerCell?: (props: TableHeaderCellSlotProps<TRecord>) => VNodeChild
empty?: () => VNodeChild
loading?: () => VNodeChild
customFilterDropdown?: (props: CustomFilterDropdownSlotProps<TRecord>) => VNodeChild
customFilterIcon?: (props: { column: ColumnType<TRecord>; filtered: boolean }) => VNodeChild
title?: (props: TableDataSlotProps<TRecord>) => VNodeChild
footer?: (props: TableDataSlotProps<TRecord>) => VNodeChild
paginationItem?: (props: TablePaginationSlotProps) => VNodeChild
summary?: () => VNodeChild
expandColumnTitle?: () => VNodeChild
}Pagination
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'
}
>Summary components
export type SummaryFixed = boolean | 'top' | 'bottom'/** 文档说明用辅助接口,不是包导出。 */
export interface VTableSummaryProps {
fixed?: SummaryFixed
}/** 文档说明用辅助接口,不是包导出。index 是必填的列索引。 */
export interface VTableSummaryCellProps {
index: number
colSpan?: number
rowSpan?: number
align?: AlignType
}