Expandable rows
Expandable rows show supplementary information right in the current table, without navigating to a detail page. They are not the same kind of feature as a tree table: a tree table handles data that is naturally hierarchical, while expandable rows handle "the current row needs an extra block of content expanded".
Live demo
defaultExpandedRowKeys expands the first row in advance; rowExpandable marks the third row as not expandable, so it shows no expand icon.
<script setup lang="ts">
import { h } from 'vue'
import { VTable } from '@vtable-guild/vtable-guild'
import type { Expandable, TableColumnsType } from '@vtable-guild/vtable-guild'
interface OrderRow {
key: string
no: string
customer: string
amount: number
note: string
refundable: boolean
}
const columns: TableColumnsType<OrderRow> = [
{ title: '订单号', dataIndex: 'no', key: 'no' },
{ title: '客户', dataIndex: 'customer', key: 'customer' },
{
title: '金额',
dataIndex: 'amount',
key: 'amount',
align: 'right',
customRender: ({ text }) => `¥ ${Number(text).toLocaleString()}`,
},
]
const dataSource: OrderRow[] = [
{
key: '1',
no: 'SO-20260712-001',
customer: '云图科技',
amount: 128400,
note: '客户要求分两批发货,第二批等对方仓库腾空后再排期。',
refundable: true,
},
{
key: '2',
no: 'SO-20260712-002',
customer: '衡石数据',
amount: 42600,
note: '已开票,发票号 25017788。',
refundable: true,
},
{
key: '3',
no: 'SO-20260713-004',
customer: '南岭制造',
amount: 9800,
note: '(此行不可展开)',
refundable: false,
},
]
const expandable: Expandable<OrderRow> = {
defaultExpandedRowKeys: ['1'],
// rowExpandable 返回 false 的行不显示展开图标
rowExpandable: (record) => record.refundable,
expandedRowRender: (record) =>
h('div', { style: 'padding: 4px 0; font-size: 13px; line-height: 1.7' }, [
h('div', `备注:${record.note}`),
h('div', { style: 'opacity: 0.65' }, `可退款:${record.refundable ? '是' : '否'}`),
]),
}
</script>
<template>
<VTable row-key="key" :columns="columns" :data-source="dataSource" :expandable="expandable" />
</template>Basic example
<script setup lang="ts">
import { VTable, type TableColumnsType, type Expandable } from '@vtable-guild/vtable-guild'
interface UserRow {
key: string
name: string
role: string
city: string
}
const columns: TableColumnsType<UserRow> = [{ title: 'Name', dataIndex: 'name', key: 'name' }]
const expandable: Expandable<UserRow> = {
expandRowByClick: true,
expandedRowRender: (record) =>
`${record.name} works on ${record.role} and is based in ${record.city}`,
}
const dataSource: UserRow[] = [{ key: '1', name: 'Ada', role: 'product design', city: 'Shanghai' }]
</script>
<template>
<VTable row-key="key" :columns="columns" :data-source="dataSource" :expandable="expandable" />
</template>Common extension points
expandRowByClickExpand by clicking anywhere on the rowrowExpandable: (record: TRecord) => booleanDecide which rows can expand based on application conditionsexpandIcon: NonNullable<Expandable<TRecord>['expandIcon']>Customize the expand iconshowExpandColumn: falseHide the dedicated expand column and keep only expanding by row click
TRecord is specified by the UserRow in Expandable<UserRow>; the expand icon's parameter object contains expanded, record, expandable and onExpand. See the declarations at the end of the page for the full fields and callback signatures.
Expand column position and title
expandable.expandIconColumnIndex sets the position of the expand column among the application columns, starting from 0; the selection column still stays in front. Negative and out-of-range values are clamped to the valid range. An explicit EXPAND_COLUMN placeholder takes precedence over this position setting.
expandable.columnTitle accepts a text or numeric title. For complex content, use #expandColumnTitle, which takes precedence over columnTitle; the selection column's title is still configured through rowSelection.columnTitle. The tree indent icon can also use expandIconColumnIndex to pick an application column.
When to use
- Inline detail previews
- Supplementary descriptions, tags and notes
- Content that clearly exceeds what a cell can hold but does not warrant a separate detail page
Known limitations
- preserve-expanded-content is not supported: when a row is collapsed, its expanded content is removed from the DOM and rendered again the next time the row expands. The original element-plus Table (2.9.7+) provides a
preserve-expanded-contentattribute that keeps the DOM state of expanded content; vtable-guild does not implement this yet. If the expanded content contains a form or stateful components, their state is lost after collapsing.
API
TRecord is the application row type. See the API Reference for the full table configuration.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
expandable | Expandable<TRecord> | - | Enables expandable rows. |
rowKey | string | ((record: TRecord) => Key) | 'key' | Unique row identity. Selection state is recorded by row key, so it must be stable and unique. |
Expandable
| 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. |
Slots
| Slot | Payload type | Description |
|---|---|---|
expandColumnTitle | () | Custom expand column title. |
Theming
The classes of the expanded content and the expand button can be overridden through the per-instance ui or the global theme.table.slots. To adjust colors or sizes, use the CSS variables below. See Three-layer theme overrides for the override order.
ui slots
| Slot | Description |
|---|---|
expandIcon | Base styles of the expand button. |
expandIconExpanded | Expanded state. |
expandIconCollapsed | Collapsed state. |
expandIconSpaced | Placeholder for rows that cannot be expanded. |
expandIconDisabled | Disabled state. |
expandIconSymbol | Symbol container of the expand icon. |
expandIconSymbolExpanded | Expanded symbol state. |
expandIconSymbolCollapsed | Collapsed symbol state. |
expandedRow | Expanded row <tr>. |
expandedRowCell | Expanded content <td>. |
Preset defaults
Use the tabs below to switch between the default classes of the two presets. For how to override utilities in the default precompiled mode, see Prefix and override rules.
createVTableGuild({
theme: {
table: {
slots: {
expandIcon: "relative inline-flex h-[17px] w-[17px] shrink-0 items-center justify-center origin-center scale-[0.941176] p-0 leading-[17px] rounded-[6px] border border-[color:var(--vtg-table-border-color,#d9d9d9)] bg-[color:var(--vtg-table-bg,#fff)] text-[color:var(--vtg-table-text-color)] cursor-pointer align-sub select-none transition-[border-color,background-color,color] duration-200 hover:border-[color:var(--color-primary)] hover:text-[color:var(--color-primary)] focus:border-[color:var(--color-primary)] focus:text-[color:var(--color-primary)] active:border-[color:var(--color-primary)] active:text-[color:var(--color-primary)] before:absolute before:left-[3px] before:right-[3px] before:top-[7px] before:h-px before:bg-current before:content-[''] after:absolute after:bottom-[3px] after:left-[7px] after:top-[3px] after:w-px after:origin-center after:bg-current after:content-[''] after:transition-transform after:duration-200",
expandIconExpanded: 'after:scale-y-0',
expandIconCollapsed: 'after:scale-y-100',
expandIconSpaced: 'cursor-default border-transparent bg-transparent before:hidden after:hidden invisible',
expandIconDisabled: 'cursor-default border-transparent bg-transparent before:hidden after:hidden invisible',
expandIconSymbol: 'hidden',
expandIconSymbolExpanded: '',
expandIconSymbolCollapsed: '',
expandedRow: '',
expandedRowCell: 'bg-[color:var(--vtg-table-expanded-row-bg,#fafafa)]',
},
},
},
})createVTableGuild({
themePreset: 'element-plus',
theme: {
table: {
slots: {
expandIcon: 'inline-flex h-[23px] w-[23px] shrink-0 items-center justify-center border-0 bg-transparent p-0 text-[color:var(--vtg-table-text-color)] cursor-pointer align-middle transition-[color,transform] duration-200',
expandIconExpanded: '',
expandIconCollapsed: '',
expandIconSpaced: 'cursor-default opacity-0',
expandIconDisabled: 'cursor-not-allowed text-[color:var(--color-muted)]',
expandIconSymbol: 'inline-flex items-center justify-center text-[12px] leading-none transition-transform duration-300 [&>svg]:h-[1em] [&>svg]:w-[1em]',
expandIconSymbolExpanded: 'rotate-90',
expandIconSymbolCollapsed: 'rotate-0',
expandedRow: '',
expandedRowCell: 'bg-[color:var(--vtg-table-expanded-row-bg,#fafafa)]',
},
},
},
})CSS variables
The table lists the defaults in light mode. Dark mode can be overridden separately under .dark.
| Variable | Purpose | antdv | element-plus |
|---|---|---|---|
--vtg-table-bg | Main table background, used by areas such as table and td | var(--color-surface) | var(--color-surface) |
--vtg-table-text-color | Body text color | var(--color-on-surface) | var(--color-text-regular) |
--vtg-table-border-color | Table border and cell dividers | var(--color-default) | var(--color-default) |
--color-primary | Theme primary color, used for drag handle hover, button highlights, field states and more | #1677ff | #409eff |
--vtg-table-expanded-row-bg | Expanded row content background | undeclared, falls back to #fafafa | undeclared, falls back to #fafafa |
Type Declarations
The declarations below cover the expand state, detail rendering, icon parameters and expand callbacks. VNodeChild is Vue's renderable content type; see the Type reference for the other dependent types.
View type declarations
export type Key = string | numberexport 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>
}export type RowClassName<TRecord = Record<string, any>> = (
record: TRecord,
index: number,
indent: number,
) => string