Title, footer and summary
This set of features adds structured information above and below the table. Their roles can be summarized as:
titleThe information area above the tablefooterSupplementary notes below the tablesummarySummary rows directly related to the current data
title can also hold a VTableToolbar, which combines the title, refresh, density, column settings and application buttons. Add actions such as export through the toolbar's #actions; see Toolbar for a complete example. The outer VTable #title provides { data }, while the inner toolbar slots provide the tool state and methods; the two have different scopes.
Live demo
<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>Basic example
Import the summary row component as VTableSummary; Row / Cell are attached to it. The index of a Cell corresponds to the column index.
<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: 'Name', key: 'name', dataIndex: 'name' },
{ title: 'Score', 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) =>
`Department performance overview · ${data.length} people`
const footer: NonNullable<TableProps<ScoreRow>['footer']> = () => 'Data updated: today 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">Total</VTableSummary.Cell>
<VTableSummary.Cell :index="1" align="right">{{ totalScore }}</VTableSummary.Cell>
</VTableSummary.Row>
</VTableSummary>
</template>
</VTable>
</template>The function signature of both title and footer is (data: TRecord[]) => VNodeChild; with pagination enabled they receive the data displayed on the current page. The corresponding #title / #footer slots receive { data: TRecord[] }, while #summary provides no parameters. VNodeChild is Vue's renderable content type.
When to use which
titleTitles, statistics summaries, filter descriptions and batch action hintsfooterDescriptive text, update times and notes on how the figures are calculatedsummaryAmount totals, averages, counts and summaries of the selected items
Usage boundaries
- When you only need to place a piece of descriptive text, prefer
titleorfooter summaryis better suited to results directly related to the current data than to general descriptions- If the page already has a complete card header around the table, the table
titlecan carry only local state information
API
TRecord is the application row type. See the API Reference for the full table configuration.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
title | (data: TRecord[]) => VNodeChild | - | Render function for the table title area. |
footer | (data: TRecord[]) => VNodeChild | - | Render function for the table footer area. |
sticky | boolean | TableSticky | false | Sticky header and summary row; for the object form, see options. |
Slots
| Slot | Payload type | Description |
|---|---|---|
title | TableDataSlotProps<TRecord> | Custom title area. |
footer | TableDataSlotProps<TRecord> | Custom footer area. |
summary | () | Custom summary area. |
VTableSummary
| 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. |
Theming
The classes of the title, footer and summary areas 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 |
|---|---|
title | Table title area. |
footer | Table footer area. |
summary | Summary container. |
summaryRow | Summary <tr>. |
summaryCell | Summary <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: {
title: 'bg-[color:var(--vtg-table-header-bg)] text-[color:var(--vtg-table-text-color)]',
footer: 'bg-[color:var(--vtg-table-header-bg)] text-[color:var(--vtg-table-text-color)]',
summary: '',
summaryRow: 'bg-[color:var(--vtg-table-header-bg)]',
summaryCell: 'font-semibold bg-[color:var(--vtg-table-header-bg)] text-[color:var(--vtg-table-text-color)] border-b border-[color:var(--vtg-table-border-color)]',
},
variants: {
bordered: {
true: {
title: 'border-b border-[color:var(--vtg-table-border-color)]',
footer: 'border-t border-[color:var(--vtg-table-border-color)]',
summaryCell: 'border-r border-[color:var(--vtg-table-border-color)] last:border-r-0',
},
},
},
compoundSlots: [
{
slots: ['title', 'footer', 'summaryCell'],
size: 'large',
class: 'px-[var(--vtg-table-cell-padding-inline-lg)] py-[var(--vtg-table-cell-padding-block-lg)]',
},
{
slots: ['title', 'footer', 'summaryCell'],
size: 'middle',
class: 'px-[var(--vtg-table-cell-padding-inline-md)] py-[var(--vtg-table-cell-padding-block-md)]',
},
{
slots: ['title', 'footer', 'summaryCell'],
size: 'small',
class: 'px-[var(--vtg-table-cell-padding-inline-sm)] py-[var(--vtg-table-cell-padding-block-sm)]',
},
],
defaultVariants: {
size: 'large',
bordered: false,
},
},
},
})createVTableGuild({
themePreset: 'element-plus',
theme: {
table: {
slots: {
title: 'bg-[color:var(--vtg-table-header-bg)] text-[color:var(--vtg-table-text-color)] font-medium',
footer: 'bg-[color:var(--vtg-table-header-bg)] text-[color:var(--vtg-table-text-color)]',
summary: '',
summaryRow: 'bg-[color:var(--vtg-table-header-bg)]',
summaryCell: 'font-medium bg-[color:var(--vtg-table-header-bg)] text-[color:var(--vtg-table-text-color)] border-b border-[color:var(--vtg-table-border-color)]',
},
variants: {
bordered: {
true: {
title: 'border-b border-[color:var(--vtg-table-border-color)]',
footer: 'border-t border-[color:var(--vtg-table-border-color)]',
summaryCell: 'border-r border-[color:var(--vtg-table-border-color)] last:border-r-0',
},
},
},
compoundSlots: [
{
slots: ['title', 'footer', 'summaryCell'],
size: 'large',
class: 'px-[var(--vtg-table-cell-padding-inline-lg)] py-[var(--vtg-table-cell-padding-block-lg)]',
},
{
slots: ['title', 'footer', 'summaryCell'],
size: 'middle',
class: 'px-[var(--vtg-table-cell-padding-inline-md)] py-[var(--vtg-table-cell-padding-block-md)]',
},
{
slots: ['title', 'footer', 'summaryCell'],
size: 'small',
class: 'px-[var(--vtg-table-cell-padding-inline-sm)] py-[var(--vtg-table-cell-padding-block-sm)]',
},
],
defaultVariants: {
size: 'middle',
bordered: false,
},
},
},
})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-header-bg | Background of the header, title, footer and summary row | var(--color-surface-hover) | 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) |
--vtg-table-cell-padding-inline-lg | Horizontal padding for the large size | 16px | 12px |
--vtg-table-cell-padding-block-lg | Vertical padding for the large size | 16px | 12px |
--vtg-table-cell-padding-inline-md | Horizontal padding for the middle size | 8px | 12px |
--vtg-table-cell-padding-block-md | Vertical padding for the middle size | 12px | 8px |
--vtg-table-cell-padding-inline-sm | Horizontal padding for the small size | 8px | 12px |
--vtg-table-cell-padding-block-sm | Vertical padding for the small size | 8px | 4px |
Type Declarations
The function declarations of title / footer belong to TableProps<TRecord>, and the slot parameters use TableDataSlotProps<TRecord>. The props are an excerpt of the relevant fields; TitleFooterFields, VTableSummaryProps and VTableSummaryCellProps are documentation helper interfaces, not package exports. VTableSummary.Row has no custom props. See the Type reference for the full declarations.
View type declarations
/** TableProps 节选;文档辅助接口,不是包导出。 */
export interface TitleFooterFields<TRecord extends object = Record<string, any>> {
title?: (data: TRecord[]) => VNodeChild
footer?: (data: TRecord[]) => VNodeChild
}export interface TableDataSlotProps<TRecord extends object = Record<string, any>> {
data: TRecord[]
}export type SummaryFixed = boolean | 'top' | 'bottom'/** 文档说明用辅助接口,不是包导出。 */
export interface VTableSummaryProps {
fixed?: SummaryFixed
}/** 文档说明用辅助接口,不是包导出。index 是必填的列索引。 */
export interface VTableSummaryCellProps {
index: number
colSpan?: number
rowSpan?: number
align?: AlignType
}