展开行
展开行适合在不跳转详情页的前提下,直接在当前表格里展示补充信息。它和树形表格不是同一类能力:树形表格处理的是数据天然分层,展开行处理的是“当前行需要额外展开一块内容”。
在线示例
defaultExpandedRowKeys 预展开第一行;第三行被 rowExpandable 判定为不可展开,不显示展开图标。
vue
<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>基础示例
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: '姓名', dataIndex: 'name', key: 'name' }]
const expandable: Expandable<UserRow> = {
expandRowByClick: true,
expandedRowRender: (record) => `${record.name} 负责 ${record.role},所在城市为 ${record.city}`,
}
</script>
<template>
<VTable row-key="key" :columns="columns" :data-source="dataSource" :expandable="expandable" />
</template>常见扩展点
expandRowByClick整行点击展开rowExpandable(record)按业务条件决定哪些行可展开expandIcon(props)自定义展开图标showExpandColumn: false隐藏独立展开列,只保留行点击展开
什么时候用
- 行内详情预览
- 补充说明、标签、备注信息
- 内容明显超出单元格承载范围,但又不值得单独跳转详情页
已知限制
- 不支持 preserve-expanded-content:收起行时,展开内容会从 DOM 中销毁,再次展开时重新渲染。element-plus 原版 Table(2.9.7+)提供了
preserve-expanded-content属性来保留已展开内容的 DOM 状态,当前 vtable-guild 尚未实现该能力。如果展开内容包含表单或有状态组件,收起后状态会丢失。