标题、页脚与摘要行
这组能力用于在表格上下补充结构化信息。它们的分工可以简单理解为:
title表格上方的信息区footer表格下方的补充说明summary和当前数据直接相关的汇总行
在线示例
vue
<script setup lang="ts">
import { computed } from 'vue'
import { VTable, VTableSummary } from '@vtable-guild/vtable-guild'
import type { TableColumnsType } from '@vtable-guild/vtable-guild'
interface DeptRow {
key: string
dept: string
headcount: number
budget: number
used: number
}
const columns: TableColumnsType<DeptRow> = [
{ title: '部门', dataIndex: 'dept', key: 'dept' },
{ title: '人数', dataIndex: 'headcount', key: 'headcount', align: 'right' },
{
title: '预算',
dataIndex: 'budget',
key: 'budget',
align: 'right',
customRender: ({ text }) => `¥ ${Number(text).toLocaleString()}`,
},
{
title: '已支出',
dataIndex: 'used',
key: 'used',
align: 'right',
customRender: ({ text }) => `¥ ${Number(text).toLocaleString()}`,
},
]
const dataSource: DeptRow[] = [
{ key: '1', dept: '平台组', headcount: 24, budget: 1200000, used: 864000 },
{ key: '2', dept: '交易组', headcount: 41, budget: 2050000, used: 1710500 },
{ key: '3', dept: '设计系统', headcount: 6, budget: 300000, used: 182000 },
{ key: '4', dept: '质量保障', headcount: 21, budget: 940000, used: 733000 },
]
const total = computed(() =>
dataSource.reduce(
(acc, row) => ({
headcount: acc.headcount + row.headcount,
budget: acc.budget + row.budget,
used: acc.used + row.used,
}),
{ headcount: 0, budget: 0, used: 0 },
),
)
const money = (value: number) => `¥ ${value.toLocaleString()}`
</script>
<template>
<VTable
row-key="key"
bordered
:columns="columns"
:data-source="dataSource"
:title="() => '2026 财年部门预算执行'"
:footer="() => '口径:含外包成本,不含办公场地分摊'"
>
<!-- Summary 的 index 对应列下标,align 单独控制摘要单元格对齐 -->
<template #summary>
<VTableSummary>
<VTableSummary.Row>
<VTableSummary.Cell :index="0">合计</VTableSummary.Cell>
<VTableSummary.Cell :index="1" align="right">{{ total.headcount }}</VTableSummary.Cell>
<VTableSummary.Cell :index="2" align="right">{{
money(total.budget)
}}</VTableSummary.Cell>
<VTableSummary.Cell :index="3" align="right">{{ money(total.used) }}</VTableSummary.Cell>
</VTableSummary.Row>
</VTableSummary>
</template>
</VTable>
</template>基础示例
摘要行组件从 VTableSummary 导入,Row / Cell 挂在它上面。Cell 的 index 对应列下标。
vue
<script setup lang="ts">
import {
VTable,
VTableSummary,
type TableColumnsType,
type TableProps,
} from '@vtable-guild/vtable-guild'
interface ScoreRow {
key: string
name: string
score: number
}
const columns: TableColumnsType<ScoreRow> = [
{ title: '姓名', key: 'name', dataIndex: 'name' },
{ title: '分数', key: 'score', dataIndex: 'score', align: 'right' },
]
const dataSource: ScoreRow[] = [
{ key: '1', name: 'Ada', score: 95 },
{ key: '2', name: 'Grace', score: 92 },
]
const totalScore = dataSource.reduce((sum, row) => sum + row.score, 0)
const title: NonNullable<TableProps<ScoreRow>['title']> = (data) =>
`部门绩效总览 · ${data.length} 人`
const footer: NonNullable<TableProps<ScoreRow>['footer']> = () => '数据更新时间:今天 09:30'
</script>
<template>
<VTable
row-key="key"
:columns="columns"
:data-source="dataSource"
:title="title"
:footer="footer"
>
<template #summary>
<VTableSummary>
<VTableSummary.Row>
<VTableSummary.Cell :index="0">合计</VTableSummary.Cell>
<VTableSummary.Cell :index="1" align="right">{{ totalScore }}</VTableSummary.Cell>
</VTableSummary.Row>
</VTableSummary>
</template>
</VTable>
</template>title / footer 的函数签名都是 (data: TRecord[]) => VNodeChild;分页开启时接收当前页展示数据。对应的 #title / #footer 插槽接收 { data: TRecord[] },而 #summary 不提供参数。VNodeChild 是 Vue 的可渲染内容类型。
什么时候用哪一个
title标题、统计摘要、筛选说明、批量操作提示footer说明文字、更新时间、口径备注summary金额合计、平均值、总数和选中项汇总
使用边界
- 只是放一段说明文字时,优先用
title或footer summary更适合表达和当前数据直接相关的结果,而不是通用描述- 如果页面外层已经有完整卡片头部,表格
title可以只承载局部状态信息
相关页面
Type Declarations
title / footer 的函数声明属于 TableProps<TRecord>,插槽参数使用 TableDataSlotProps<TRecord>。props 为相关字段节选;TitleFooterFields、VTableSummaryProps 和 VTableSummaryCellProps 是文档辅助接口,不是包导出。VTableSummary.Row 没有自定义 props,完整声明见类型参考。
查看类型声明
ts
/** TableProps 节选;文档辅助接口,不是包导出。 */
export interface TitleFooterFields<TRecord extends object = Record<string, any>> {
title?: (data: TRecord[]) => VNodeChild
footer?: (data: TRecord[]) => VNodeChild
}ts
export interface TableDataSlotProps<TRecord extends object = Record<string, any>> {
data: TRecord[]
}ts
export type SummaryFixed = boolean | 'top' | 'bottom'ts
/** 文档说明用辅助接口,不是包导出。 */
export interface VTableSummaryProps {
fixed?: SummaryFixed
}ts
/** 文档说明用辅助接口,不是包导出。index 是必填的列索引。 */
export interface VTableSummaryCellProps {
index: number
colSpan?: number
rowSpan?: number
align?: AlignType
}