Skip to content

ui Slot 参考 ​

VTable 的 ui prop 是实例级别的样式覆盖入口。每个 key 对应一个 theme slot,值为 Tailwind CSS class 字符串,会与预设默认 class 通过 cn() 智能合并。

vue
<VTable
  :columns="columns"
  :data-source="data"
  :ui="{
    th: 'bg-blue-50',
    td: 'align-top',
  }"
/>

TIP

安装并导入 @vtable-guild/vtable-guild 后,在 TypeScript 项目中 ui prop 的所有 slot key 都有自动补全。


这页不只给 ui 用 ​

这页列出的 slot 和 variant,不只是 ui prop 的参考表,也对应全局 theme 的写法:

  • ui.th 对应 theme.table.slots.th
  • ui.td 对应 theme.table.slots.td
  • hoverable.true.td 对应 theme.table.variants.hoverable.true.td
  • size: 'small' 对应 theme.table.defaultVariants.size = 'small'

也就是说,这页可以当成“Table 主题系统可覆盖项总表”来看。

从 slot 表映射到全局 theme ​

ts
createVTableGuild({
  theme: {
    table: {
      slots: {
        th: 'bg-slate-50 text-slate-900',
        td: 'align-top',
      },
      variants: {
        hoverable: {
          true: {
            td: 'group-hover/row:bg-blue-50',
          },
        },
      },
      defaultVariants: {
        size: 'small',
      },
    },
  },
})

如果你要的是应用级统一规范,优先看 三层主题覆盖。如果你只是改单张表,再回到 ui。

快速示例:修改行 hover 背景色 ​

行 hover 效果由 hoverable variant 控制,hover 高亮通过 JS 状态驱动,能正确处理跨行合并单元格。自定义 hover 背景色推荐覆盖 CSS 变量:

方式一:覆盖 CSS 变量(推荐) ​

css
:root {
  --vtg-table-row-hover-bg: #e6f7ff;
}

方式二:通过 ui prop 覆盖 tdRowHover slot ​

vue
<VTable :columns="columns" :data-source="data" :ui="{ tdRowHover: 'bg-blue-50' }" />

方式三:通过全局 theme ​

ts
app.use(
  createVTableGuild({
    theme: {
      table: {
        slots: {
          tdRowHover: 'bg-blue-50',
        },
      },
    },
  }),
)

完整 Slot 列表 ​

以下按功能分组列出所有可用的 theme slot key。它们既可用于 ui,也可用于全局 theme.table.slots。

核心结构 ​

Slot说明
root表格最外层容器。控制字体、字号、行高。
wrapper<table> 元素的滚动包裹层。
rootAutoHeightscroll.y: 'auto' 时叠加在 root 上的自动高度布局(填满父容器)。
wrapperAutoHeightscroll.y: 'auto' 时叠加在 wrapper 上的自动高度布局(吃剩余高度)。
table<table> 元素。控制背景色、文字色、边框间距。
thead<thead> 元素。
tbody<tbody> 元素。
tr<tr> 元素。默认带 group/row,供子元素做 hover 匹配。
th表头单元格 <th>。控制背景、文字色、边框和分割线。
td数据单元格 <td>。控制背景、文字色、边框;hover、选中、斑马纹通过 variant 追加。

表头与单元格包装 ​

Slot说明
headerCellInner表头单元格内部的 flex 包裹层。
bodyCellEllipsisellipsis 列内容的文本截断层。
headerHelp列 tooltip 的表头说明图标。
cellContentcopyable 列的内容与复制按钮包裹层。
copyButtoncopyable 列的复制按钮。

分组表头 ​

Slot说明
groupedHeaderTable多级表头中的内层 <table>。
groupedHeaderTh分组表头 <th>。
groupedHeaderTd分组表头 <td>。

排序 ​

Slot说明
thSortable可排序列的 <th> 附加样式。
thSorted已激活排序的列 <th> 背景。
tdSorted已激活排序的列 <td> 背景。
sortButton排序图标容器。
sortIconDown降序图标的间距调整。
sortAreaOuter排序区最外层 flex 包裹。
sortAreaWrapper标题和排序图标之间的 flex 包裹。
sortAreaTitle排序标题文本容器。

筛选图标 ​

Slot说明
filterIconWrapper筛选图标包裹容器。
filterIcon筛选触发图标本身。

筛选下拉面板 ​

Slot说明
filterDropdown筛选面板根容器。
filterDropdownList筛选选项列表容器。
filterDropdownItem单个筛选项。
filterDropdownItemSelected选中项样式。
filterDropdownItemSelectedSingle单选(filterMultiple: false)下的选中项附加样式。
filterDropdownItemHoverhover 项样式。
filterDropdownContentWrapper选项内容包裹层。
filterDropdownActions底部操作栏。
filterDropdownResetButton底部「重置」按钮的附加样式。
filterDropdownConfirmButton底部「确定」按钮的附加样式。
filterDropdownSearch搜索区外层。
filterDropdownSearchField搜索输入框容器。
filterDropdownSearchIcon搜索图标。
filterDropdownSearchInput搜索输入框。
filterDropdownListEmpty空结果提示。

筛选树形结构 ​

Slot说明
filterDropdownSwitcher树节点展开/折叠按钮。
filterDropdownSwitcherExpanded展开状态。
filterDropdownSwitcherCollapsed折叠状态。
filterDropdownSwitcherNoop不可切换节点占位。
filterDropdownTreeWrapper树列表包裹层。
filterDropdownTreeList树列表 <ul>。
filterDropdownTreeItem单个树节点行。
filterDropdownTreeContentWrapper树节点内容包裹层。
filterDropdownTreeItemSelected选中节点样式。
filterDropdownTreeItemMatched搜索命中节点样式。
filterDropdownTreeCheckAll“全选” 行。

空状态 ​

Slot说明
empty空状态根容器。
emptyWrapper空状态内容包裹层。
emptyIcon空状态图标区域。
emptyText空状态文字。

加载态 ​

Slot说明
loading覆盖整张表的 loading 遮罩层。
loadingSpinnerloading 图标。

行选中 ​

Slot说明
tdSelected选中行的 <td> 背景。
tdRowHoverhover 时普通行的 <td> 背景。
tdRowSelectedHoverhover 时选中行的 <td> 背景叠加层。

行拖拽排序 ​

Slot说明
trDragging拖拽中的行 <tr>。
trDropAbove放置目标行(插入到其上方)的 <tr> 指示线。
trDropBelow放置目标行(插入到其下方)的 <tr> 指示线。

行选择下拉 ​

Slot说明
selectionDropdown行选择下拉面板。
selectionDropdownItem行选择下拉项。
selectionExtra行选择列头部的额外触发图标。

标题、页脚与摘要 ​

Slot说明
title表格标题区域。
footer表格页脚区域。
summary摘要容器。
summaryRow摘要 <tr>。
summaryCell摘要 <td>。

固定列与固定表头 ​

Slot说明
headerWrapper固定表头模式下的表头滚动包裹层。
bodyWrapper固定表头模式下的表体滚动包裹层。
fixedCell固定列单元格。
fixedDividerLeft左固定列分隔线。
fixedDividerRight右固定列分隔线。
fixedShadowLeft左固定列阴影层。
fixedShadowRight右固定列阴影层。
fixedShadowLeftHidden左侧阴影隐藏状态。
fixedShadowRightHidden右侧阴影隐藏状态。

展开行 ​

Slot说明
expandIcon展开按钮基础样式。
expandIconExpanded展开状态。
expandIconCollapsed折叠状态。
expandIconSpaced不可展开行的占位符。
expandIconDisabled禁用状态。
expandIconSymbol展开图标的 symbol 容器。
expandIconSymbolExpanded展开 symbol 状态。
expandIconSymbolCollapsed折叠 symbol 状态。
expandedRow展开行 <tr>。
expandedRowCell展开内容 <td>。

树形展开 ​

treeExpandIconLoading 与 treeExpandIconError 分别控制懒加载反馈与可重试错误;颜色、大小与动画由预设层定义。

Slot说明
treeExpandIcon树形展开按钮基础样式。
treeExpandIconExpanded展开状态。
treeExpandIconCollapsed折叠状态。
treeExpandIconSpaced叶子节点占位。
treeExpandIconDisabled禁用状态。
treeExpandIconSymbol树形 symbol 容器。
treeExpandIconSymbolExpanded树形展开 symbol 状态。
treeExpandIconSymbolCollapsed树形折叠 symbol 状态。
treeExpandIconLoading懒加载进行中的按钮状态。
treeExpandIconError懒加载失败后的重试按钮状态。

字段标签 ​

cellTag 控制 valueType: 'tag' 的标签外观,cellStatus 继续控制枚举状态标记。两者共享 data-status 与状态色变量;自定义 renderer 也可返回 presentation: 'tag' 使用标签主题。

Slot说明
cellStatusvalueEnum 状态标记,按 data-status 着色。
cellTagvalueType: 'tag' 或渲染器 presentation: 'tag' 的标签外观。

字段进度 ​

Slot说明
cellProgress进度整体宽度与轨道、数值之间的间距。
cellProgressTrack轨道高度、圆角与背景。
cellProgressBar填充色,支持 data-status 状态。
cellProgressText百分比文字或成功 / 错误图标。

编辑控件 ​

Slot说明
editCell已进入编辑的单元格内容容器。
editSizer稳定布局下不可见的展示内容副本,决定编辑单元格的尺寸。
editControl宿主控件的宽度和错误轮廓。
editError按字段定位的校验错误。
editTrigger单元格点击编辑模式下的可点击触发按钮。
editTriggerValue单元格点击编辑触发器内的展示文本容器。
editTriggerIcon单元格悬停或聚焦时显示的编辑图标容器。

查询区使用独立的 theme.query,见 Schema 查询区。

列宽拖拽 ​

Slot说明
resizeHandle列宽拖拽手柄。

列宽布局 ​

Slot说明
widthConstraintCell用于约束列宽的单元格。
widthConstraintInner列宽约束单元格的内部元素。
widthLayoutCell使用列宽布局时附加的单元格样式。

Variant 列表 ​

表格根据 props 应用条件样式。全局 theme.table.variants 可覆盖预设的条件 class。表格未传 size 时,可通过 theme.table.defaultVariants.size 调整默认尺寸。

Variant值默认值影响的 Slot
sizesmall / middle / largeantdv 为 large,element-plus 为 middleth、td、title、footer、summaryCell 的内边距
borderedtrue / falsefalseroot、th、td、tbody、title、footer、summaryCell 的边框
stripedtrue / falsefalsetd 和相关行状态 slot 的偶数行背景
hoverabletrue / falsetruetdRowHover、tdRowSelectedHover 控制普通行与选中行的 hover 背景
loadingtrue / falsefalseantdv 的 table 在布尔 true 时半透明并禁用指针交互。两套预设的遮罩与默认图标由 loading 和 loadingSpinner 控制。

工具栏与列设置的主题 slots ​

这两个组件有独立的主题配置:全局使用 theme.toolbar.slots / theme.columnSettings.slots,实例使用各自的 ui。VTableToolbar 内部列设置的实例样式通过 columnSettings.ui 传入;单独使用 VTableColumnSettings 时直接传 ui。

VTableToolbar ​

Slot说明
root工具栏根容器与响应式布局。
title标题区。
right业务操作和内置工具的包裹层。
actions#actions 业务按钮容器。
settings内置工具或 #settings 的容器。
search工具栏轻搜索容器。
searchGroup搜索输入区和提交按钮的组合容器。
searchField搜索文本框的外层。
searchInput搜索文本输入框。
searchSubmit搜索提交按钮。
searchClear清除搜索文本按钮。
searchIcon搜索与清除图标。
filter单行布局中的 #filter 内容容器。
extra#extra 与多行布局中的 #filter 内容容器。
action刷新、全屏等内置按钮。
icon内置工具图标。
loadingIcon刷新加载动画。

VTableColumnSettings ​

Slot说明
root密度与列设置触发器容器。
trigger列设置按钮。
densityTrigger密度按钮。
popup列设置浮层。
densityPopup密度浮层。
density密度菜单选项。
header列设置面板头部。
heading全选标题。
reset重置按钮。
columns列列表。
children嵌套子列列表。
item列列表项。
row列选项行,作为拖拽载体。
rowDragging拖拽中的源行描边。
rowDropAbove目标行的上插入线。
rowDropBelow目标行的下插入线。
rowDropDot插入线左端的圆点。
dragHandle拖拽手柄。
pinActions固定位置按钮组。
pinAction固定位置按钮。
pinIcon固定位置图标。
group按固定位置划分的列组容器。
groupTitle固定位置分组标题。
groupColumns组内列列表。
label列选项标签。
checkboxControl复选框容器。
checkbox复选框输入元素。
checkMark选中标记。
indeterminateMark半选标记。
labelText列选项标签文字。
empty无可配置列时的提示。

主题 slot 用来改样式;Vue 内容插槽 #actions、#settings 和 #columnLabel 用来扩展内容,属于工具栏或列设置组件。完整示例见 工具栏与业务扩展。

分页、批量提示与查询区的主题 slots ​

分页使用全局 theme.pagination.slots。批量操作提示条和 Schema 查询区也有各自的全局主题和实例 ui。

分页 ​

Slot说明
root分页根容器。
layout自定义分页布局的两区容器。
left分页布局左区。
right分页布局右区。
extension自定义分页内容的容器。
pages页码与前后导航按钮容器。
item页码与导航按钮。
active当前页码附加样式。
jump跳过一组页码的按钮。
jumpEllipsis跳页按钮中的省略号。
jumpIcon跳页按钮悬停时显示的图标。
controls每页条数与快速跳转等控件区域。
simpleControls简洁模式控件区域。
simpleInput简洁模式页码输入框附加样式。
slash当前页与总页数之间的分隔符。
go快速跳转确认按钮。
input页码输入框。
select每页条数选择按钮。
popup每页条数下拉面板。
option每页条数下拉选项。
optionActive已选每页条数选项附加样式。
total总条数文字。
icon分页按钮图标。

批量操作提示条 ​

Slot说明
wrapper显隐过渡与高度折叠的外层容器。
content包含提示条前间距的内容容器。
root批量操作提示条视觉容器。
info选中数量或 #info 自定义内容的容器。
text默认选中数量文字。
clear清空选择按钮。
option清空选择与批量操作区域的容器。
actions批量操作内容容器。

Schema 查询区 ​

Slot说明
rootSchema 查询区根容器。
fieldsQueryFilter 栅格或 LightFilter 标签容器。
field单个查询字段布局。
label字段标签。
control宿主控件容器。
error单字段错误。
actions查询、重置与折叠操作区。
feedback查询区整体错误反馈。
collapse展开或折叠字段的入口。

进一步阅读 ​

Type Declarations ​

ui 使用 SlotProps<TableThemeConfig>,值为可选 class 字符串。下列提供全部 Table 主题 slot 与 variant props;完整全局覆盖映射见 类型参考。cn() 的辅助参数类型不是包导出。

Type Declarations
ts
export type TableSlots =
  | 'root'
  | 'wrapper'
  | 'rootAutoHeight'
  | 'wrapperAutoHeight'
  | 'table'
  | 'thead'
  | 'tbody'
  | 'widthConstraintCell'
  | 'widthConstraintInner'
  | 'widthLayoutCell'
  | 'tr'
  | 'groupedHeaderTable'
  | 'groupedHeaderTh'
  | 'groupedHeaderTd'
  | 'th'
  | 'td'
  | 'empty'
  | 'loading'
  | 'headerCellInner'
  | 'bodyCellEllipsis'
  | 'thSortable'
  | 'thSorted'
  | 'tdSorted'
  | 'sortButton'
  | 'sortIconDown'
  | 'sortAreaOuter'
  | 'sortAreaWrapper'
  | 'sortAreaTitle'
  | 'headerHelp'
  | 'cellContent'
  | 'copyButton'
  | 'cellStatus'
  | 'cellTag'
  | 'editCell'
  | 'editSizer'
  | 'editControl'
  | 'editError'
  | 'editTrigger'
  | 'editTriggerValue'
  | 'editTriggerIcon'
  | 'cellProgress'
  | 'cellProgressTrack'
  | 'cellProgressBar'
  | 'cellProgressText'
  | 'filterIconWrapper'
  | 'filterIcon'
  | 'filterDropdown'
  | 'filterDropdownList'
  | 'filterDropdownItem'
  | 'filterDropdownItemSelected'
  | 'filterDropdownItemSelectedSingle'
  | 'filterDropdownItemHover'
  | 'filterDropdownSwitcher'
  | 'filterDropdownSwitcherExpanded'
  | 'filterDropdownSwitcherCollapsed'
  | 'filterDropdownSwitcherNoop'
  | 'filterDropdownContentWrapper'
  | 'filterDropdownTreeWrapper'
  | 'filterDropdownTreeList'
  | 'filterDropdownTreeItem'
  | 'filterDropdownTreeContentWrapper'
  | 'filterDropdownTreeItemSelected'
  | 'filterDropdownTreeItemMatched'
  | 'filterDropdownTreeCheckAll'
  | 'filterDropdownActions'
  | 'filterDropdownResetButton'
  | 'filterDropdownConfirmButton'
  | 'filterDropdownSearch'
  | 'filterDropdownSearchField'
  | 'filterDropdownSearchIcon'
  | 'filterDropdownSearchInput'
  | 'filterDropdownListEmpty'
  | 'emptyWrapper'
  | 'emptyIcon'
  | 'emptyText'
  | 'loadingSpinner'
  | 'tdSelected'
  | 'tdRowHover'
  | 'tdRowSelectedHover'
  | 'trDragging'
  | 'trDropAbove'
  | 'trDropBelow'
  | 'selectionDropdown'
  | 'selectionDropdownItem'
  | 'selectionExtra'
  | 'title'
  | 'footer'
  | 'summary'
  | 'summaryRow'
  | 'summaryCell'
  | 'headerWrapper'
  | 'bodyWrapper'
  | 'fixedCell'
  | 'fixedDividerLeft'
  | 'fixedDividerRight'
  | 'fixedShadowLeft'
  | 'fixedShadowRight'
  | 'fixedShadowLeftHidden'
  | 'fixedShadowRightHidden'
  | 'expandIcon'
  | 'expandIconExpanded'
  | 'expandIconCollapsed'
  | 'expandIconSpaced'
  | 'expandIconDisabled'
  | 'expandIconSymbol'
  | 'expandIconSymbolExpanded'
  | 'expandIconSymbolCollapsed'
  | 'treeExpandIcon'
  | 'treeExpandIconExpanded'
  | 'treeExpandIconCollapsed'
  | 'treeExpandIconSpaced'
  | 'treeExpandIconDisabled'
  | 'treeExpandIconSymbol'
  | 'treeExpandIconLoading'
  | 'treeExpandIconError'
  | 'treeExpandIconSymbolExpanded'
  | 'treeExpandIconSymbolCollapsed'
  | 'expandedRow'
  | 'expandedRowCell'
  | 'resizeHandle'
ts
export type TableVariantProps = {
  size?: 'large' | 'middle' | 'small'
  bordered?: boolean
  striped?: boolean
  hoverable?: boolean
}
ts
// tableTheme 是公开的默认 antdv 主题;typeof 保留 readonly 与字面量 variant 配置。
export type TableThemeConfig = typeof tableTheme
ts
export type ToolbarThemeConfig = typeof toolbarTheme
export type ToolbarSlots = keyof ToolbarThemeConfig['slots']
ts
export type ColumnSettingsThemeConfig = typeof columnSettingsTheme
export type ColumnSettingsSlots = keyof ColumnSettingsThemeConfig['slots']
ts
export type SlotProps<T extends ThemeConfig> = Partial<Record<keyof T['slots'] & string, string>>
ts
// 以下 Theme* 辅助类型用于展开声明,不是包导出。
type ThemeSlotKeys<T extends ThemeConfig> = keyof T['slots'] & string

type ThemeVariantOverrides<T extends ThemeConfig> = {
  [TVariant in keyof NonNullable<T['variants']>]?: NonNullable<
    T['variants']
  >[TVariant] extends Record<string, unknown>
    ? {
        [TValue in keyof NonNullable<T['variants']>[TVariant]]?: NonNullable<
          T['variants']
        >[TVariant][TValue] extends string
          ? string
          : Partial<Record<ThemeSlotKeys<T>, string>>
      }
    : never
}

type ThemeDefaultVariantOverrides<T extends ThemeConfig> = {
  [TVariant in keyof NonNullable<T['defaultVariants']>]?: NonNullable<
    T['defaultVariants']
  >[TVariant] extends boolean
    ? boolean
    : string
}

type ThemeCompoundRuleOverride<T, TSlotKey extends string> = T extends string
  ? string
  : T extends boolean
    ? boolean
    : T extends readonly (infer U)[]
      ? Array<U extends string ? Extract<U, TSlotKey> : ThemeCompoundRuleOverride<U, TSlotKey>>
      : T extends object
        ? {
            [K in keyof T]?: K extends 'class'
              ? string
              : K extends 'slots'
                ? T[K] extends readonly (infer U)[]
                  ? Array<Extract<U, TSlotKey>>
                  : ThemeCompoundRuleOverride<T[K], TSlotKey>
                : ThemeCompoundRuleOverride<T[K], TSlotKey>
          }
        : T

export type ThemeOverrideConfig<T extends ThemeConfig> = {
  slots?: Partial<Record<ThemeSlotKeys<T>, string>>
  variants?: ThemeVariantOverrides<T>
  defaultVariants?: ThemeDefaultVariantOverrides<T>
  compoundVariants?: T extends { compoundVariants?: readonly (infer U)[] }
    ? Array<ThemeCompoundRuleOverride<U, ThemeSlotKeys<T>>>
    : never
  compoundSlots?: T extends { compoundSlots?: readonly (infer U)[] }
    ? Array<ThemeCompoundRuleOverride<U, ThemeSlotKeys<T>>>
    : never
}
ts
/** 文档说明用辅助类型,不是包导出。对象值按 truthy/falsy 决定是否添加对应 class。 */
type CnClassValue =
  | string
  | number
  | bigint
  | boolean
  | null
  | undefined
  | Record<string, unknown>
  | CnClassValue[]

export declare const cn: <T extends CnClassValue[]>(...classes: T) => string | undefined