Presets and locales
This part of the configuration answers two higher-level questions:
- Which UI system the overall look should match.
- Which language the table's built-in text uses, and how to override it locally.
Live demo
The same column definitions and data, with the preset and locale switched to show the effect. This is the most distinctive point of this library: changing the skin requires neither a different table nor a different API.
In an application you usually configure it once with
createVTableGuild({ themePreset }). The demo above provides a scoped context in place only to compare the two skins on the same page.
Theme presets
There are currently two built-in theme presets:
- antdv, the default preset, suited to projects that already use ant-design-vue.
- element-plus, suited to projects that already use the element-plus visual system.
Choose a preset at initialization:
app.use(
createVTableGuild({
themePreset: 'antdv',
}),
)To change to element-plus, switch on the JS side directly; no extra CSS is needed (@vtable-guild/vtable-guild/css/style, @vtable-guild/vtable-guild/css/tailwind3 and @vtable-guild/vtable-guild/css/tailwind4 all already contain the styles of every preset):
app.use(
createVTableGuild({
themePreset: 'element-plus',
}),
)You do not need to add the data-vtg-preset attribute to the HTML manually; the plugin handles it automatically. For more ways to integrate see Installation and usage.
Built-in locales
The built-in preset locales currently cover at least the two common language scenarios zh-CN and en-US, mainly including:
- Sorting tooltip text
- Filter panel text
- Empty-state text
- Loading-state text
- Row selection menu text
- Pagination, density, column settings and toolbar text
Register and override locale packs
To switch to English or customize the text, pass locale, locales and localeOverrides at the plugin layer:
app.use(
createVTableGuild({
locale: 'en-US',
locales: {
'en-US': {
table: {
header: {
sortTriggerAsc: 'Sort ascending',
sortTriggerDesc: 'Sort descending',
cancelSort: 'Cancel sorting',
filterTriggerAriaLabel: 'Filter',
},
filterDropdown: {
searchPlaceholder: 'Search filters',
emptyText: 'No filters',
resetText: 'Reset',
confirmText: 'OK',
selectAllText: 'Select all',
},
empty: { text: 'No data' },
loading: { text: 'Loading...' },
selection: {
selectAll: 'Select all',
selectInvert: 'Invert selection',
selectNone: 'Clear selection',
selectionsTriggerAriaLabel: 'Selection options',
},
},
},
},
}),
)If you only want to override a few fields, prefer localeOverrides; there is no need to rewrite the whole locale.
selection.selectionsTriggerAriaLabel is the accessible name of the bulk selection menu trigger in the header (the button name announced by screen readers), with the built-in values 选择操作 / Selection options. It is an optional field: existing locale packs do not need to add it, and the built-in text is used when it is missing.
Scoped switching
When you need to override the locale or theme styles inside a subtree, use VTableGuildConfigProvider:
<VTableGuildConfigProvider locale="en-US">
<VTable :columns="columns" :data-source="dataSource" />
</VTableGuildConfigProvider>This approach suits local comparison pages, multilingual admin consoles or embedded application modules.
The provider supports theme, cssMode, classPrefix, locale, locales and localeOverrides; see the declarations at the end of the page for the full types. themePreset and compatClass are inherited from the plugin context; the preset is configured through createVTableGuild({ themePreset }), and the provider does not have these two props.
Related pages
Pagination locale
Locale packs provide an optional pagination group; existing locale packs need no changes. Chinese and English are built in; override globally with localeOverrides.pagination, or per instance with pagination.locale (highest priority). See VTableGuildPaginationLocale for the full fields; prev_pages / next_pages are optional jump text templates, where {count} is replaced with the number of pages jumped.
localeOverrides supports deep partial overrides, including the optional pagination, columnSettings and toolbar groups, so you can pass just a few fields. The per-instance pagination.locale also supports partial overrides.
import { createVTableGuild } from '@vtable-guild/vtable-guild'
app.use(
createVTableGuild({
localeOverrides: {
pagination: { items_per_page: 'records / page' },
columnSettings: { reset: 'Restore default columns' },
toolbar: { reload: 'Reload data' },
},
}),
)Toolbar and column settings locale
columnSettings and toolbar are also optional locale groups; existing locale packs do not need to add them. Default text is built in for Chinese and English and follows the locale of the plugin or provider; use localeOverrides.columnSettings / localeOverrides.toolbar to override the global text.
VTableToolbar.locale overrides toolbar text such as refresh and fullscreen, and columnSettings.locale overrides the text of the inner column settings; when using VTableColumnSettings on its own, pass locale directly. Per-instance overrides take precedence over the global configuration. For component usage see Toolbar and Column display and order.
Type Declarations
Below are the complete configuration and locale declarations used on this page. For the types that theme overrides depend on see the Type reference. The provider props interface is a documentation helper type, not a package export.
Type Declarations
export type ThemePresetName = 'antdv' | 'element-plus'export interface VTableGuildOptions {
themePreset?: ThemePresetName
cssMode?: VTableGuildCssMode
classPrefix?: string
theme?: VTableGuildThemeOverrides
locale?: LocaleName
locales?: LocaleRegistry
localeOverrides?: DeepPartial<VTableGuildLocale>
/** 安装时读取一次,不支持运行时切换。 */
compatClass?: boolean
}export declare function createVTableGuild(options?: VTableGuildOptions): Plugin/** 文档说明用辅助接口,不是包导出。描述 Provider 可传入的配置 props。 */
export interface VTableGuildConfigProviderProps {
theme?: VTableGuildThemeOverrides
cssMode?: VTableGuildCssMode
classPrefix?: string
locale?: LocaleName
locales?: LocaleRegistry
localeOverrides?: DeepPartial<VTableGuildLocale>
}export interface VTableGuildContext {
themePreset: ThemePresetName
cssMode: VTableGuildCssMode
classPrefix: string
theme: VTableGuildThemeOverrides
locale: LocaleName
locales: LocaleRegistry
localeOverrides: DeepPartial<VTableGuildLocale>
compatClass?: boolean
}export declare const VTABLE_GUILD_INJECTION_KEY: InjectionKey<VTableGuildContext>export type LocaleName = stringexport type BuiltInLocaleName = 'zh-CN' | 'en-US'export type LocaleRegistry = Record<LocaleName, VTableGuildLocale>export type DeepPartial<T> = {
[K in keyof T]?: NonNullable<T[K]> extends Array<infer U>
? Array<DeepPartial<U>>
: NonNullable<T[K]> extends object
? DeepPartial<T[K]>
: T[K]
}export interface VTableGuildLocale {
table: VTableGuildTableLocale
pagination?: VTableGuildPaginationLocale
columnSettings?: VTableGuildColumnSettingsLocale
toolbar?: VTableGuildToolbarLocale
selectionAlert?: VTableGuildSelectionAlertLocale
}export interface VTableGuildTableLocale {
tree?: { expand: string; collapse: string; retry: string }
cell?: {
copy: string
copied: string
copyFailed: string
edit?: string
clickToEdit?: string
cancelEdit?: string
}
header: VTableGuildTableHeaderLocale
filterDropdown: VTableGuildTableFilterDropdownLocale
empty: VTableGuildTableEmptyLocale
loading: VTableGuildTableLoadingLocale
selection: VTableGuildTableSelectionLocale
}export interface VTableGuildTableHeaderLocale {
sortTriggerAsc: string
sortTriggerDesc: string
cancelSort: string
filterTriggerAriaLabel: string
}export interface VTableGuildTableFilterDropdownLocale {
searchPlaceholder: string
emptyText: string
resetText: string
confirmText: string
selectAllText: string
}export interface VTableGuildTableEmptyLocale {
text: string
}export interface VTableGuildTableLoadingLocale {
text: string
}export interface VTableGuildTableSelectionLocale {
selectAll: string
selectInvert: string
selectNone: string
/** 表头批量选择菜单入口的无障碍名称;可选,旧语言包无需补齐。 */
selectionsTriggerAriaLabel?: string
}export interface VTableGuildPaginationLocale {
items_per_page: string
jump_to: string
jump_to_confirm: string
page: string
prev_page: string
next_page: string
prev_5: string
next_5: string
prev_3: string
next_3: string
/** {count} 会被替换为跳转页数。 */
prev_pages?: string
next_pages?: string
navigation: string
page_size: string
}export interface VTableGuildColumnSettingsLocale {
fixed?: string
fixedLeft?: string
fixedRight?: string
unfixed?: string
mixed?: string
move?: string
title: string
reset: string
density: string
large: string
middle: string
small: string
columns: string
empty: string
}export interface VTableGuildToolbarLocale {
searchPlaceholder?: string
search?: string
clearSearch?: string
label: string
reload: string
fullScreen: string
exitFullScreen: string
}export declare const paginationZhCN: VTableGuildPaginationLocale
export declare const paginationEnUS: VTableGuildPaginationLocale
export declare const elementPlusPaginationZhCN: VTableGuildPaginationLocale
export declare const elementPlusPaginationEnUS: VTableGuildPaginationLocale