Skip to content

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.

Edit in Playground

Basic example ​

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

  • expandRowByClick Expand by clicking anywhere on the row
  • rowExpandable: (record: TRecord) => boolean Decide which rows can expand based on application conditions
  • expandIcon: NonNullable<Expandable<TRecord>['expandIcon']> Customize the expand icon
  • showExpandColumn: false Hide 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-content attribute 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 ​

PropTypeDefaultDescription
expandableExpandable<TRecord>-Enables expandable rows.
rowKeystring | ((record: TRecord) => Key)'key'Unique row identity. Selection state is recorded by row key, so it must be stable and unique.

Expandable ​

FieldTypeDefaultDescription
expandedRowRender(record: TRecord, index: number, indent: number, expanded: boolean) => VNodeChild-Render function for the expanded row content.
expandedRowKeysKey[]-Controlled expanded row keys.
defaultExpandedRowKeysKey[]-Default expanded row keys.
expandRowByClickbooleanfalseExpands 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.
columnWidthnumber | string-Width of the expand column.
fixed'left' | 'right' | true-Fixed position of the expand column; true is equivalent to 'left'.
defaultExpandAllRowsbooleanfalseExpands all rows by default.
rowExpandable(record: TRecord) => boolean-Determines whether a row can be expanded.
showExpandColumnbooleantrueWhether to show the expand column.
expandIconColumnIndexnumber0Zero-based position of the expand column among the application columns. An explicit EXPAND_COLUMN placeholder takes precedence.
columnTitlestring | number''Title of the expand column; can be overridden by #expandColumnTitle.
expandedRowClassNamestring | RowClassName<TRecord>-Class of the expanded row.

Slots ​

SlotPayload typeDescription
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 ​

SlotDescription
expandIconBase styles of the expand button.
expandIconExpandedExpanded state.
expandIconCollapsedCollapsed state.
expandIconSpacedPlaceholder for rows that cannot be expanded.
expandIconDisabledDisabled state.
expandIconSymbolSymbol container of the expand icon.
expandIconSymbolExpandedExpanded symbol state.
expandIconSymbolCollapsedCollapsed symbol state.
expandedRowExpanded row <tr>.
expandedRowCellExpanded 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.

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

VariablePurposeantdvelement-plus
--vtg-table-bgMain table background, used by areas such as table and tdvar(--color-surface)var(--color-surface)
--vtg-table-text-colorBody text colorvar(--color-on-surface)var(--color-text-regular)
--vtg-table-border-colorTable border and cell dividersvar(--color-default)var(--color-default)
--color-primaryTheme primary color, used for drag handle hover, button highlights, field states and more#1677ff#409eff
--vtg-table-expanded-row-bgExpanded row content backgroundundeclared, falls back to #fafafaundeclared, 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
ts
export type Key = string | number
ts
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>
}
ts
export type RowClassName<TRecord = Record<string, any>> = (
  record: TRecord,
  index: number,
  indent: number,
) => string