Toolbar
VTableToolbar provides a title, an application action area and common tools. Its layout follows React ProTable, and it supports the Ant Design Vue and Element Plus presets. Put it in the title slot of VTable to use it.
Reload, density and column settings are provided by default; fullscreen is opt-in. Application capabilities such as export, create and batch actions are added through slots, and can use buttons from the UI library your project already has installed.
Adding an export button
The "Export CSV" button below comes from #actions and is displayed side by side with the built-in tools. The example reads data from the title slot and the toolbar's controlled column configuration, and exports only the visible fields of the currently displayed data; after column settings, pagination or filtering change, the application can choose to export the current page, all data or the selected records.
<script setup lang="ts">
import { onBeforeUnmount, ref, shallowRef } from 'vue'
import { Button, VTable, VTableToolbar } from '@vtable-guild/vtable-guild'
import type { TableColumnsType, TableColumnSettingsSize } from '@vtable-guild/vtable-guild'
interface Member {
key: number
name: string
city: string
status: string
}
const columns = shallowRef<TableColumnsType<Member>>([
{ key: 'name', title: '姓名', dataIndex: 'name' },
{ key: 'city', title: '城市', dataIndex: 'city' },
{ key: 'status', title: '状态', dataIndex: 'status', visible: false },
])
const rows: Member[] = [
{ key: 1, name: '陈嘉', city: '杭州', status: '在职' },
{ key: 2, name: '苏晚', city: '上海', status: '在职' },
{ key: 3, name: '周野', city: '深圳', status: '休假' },
]
const size = ref<TableColumnSettingsSize>('middle')
const loading = ref(false)
const refreshes = ref(0)
const csv = ref('')
let refreshTimer: ReturnType<typeof setTimeout> | undefined
onBeforeUnmount(() => clearTimeout(refreshTimer))
function reload() {
loading.value = true
// Replace this sample with your data-loading function and clear loading in finally.
refreshTimer = setTimeout(() => {
refreshes.value++
loading.value = false
}, 500)
}
function exportCsv(data: Member[], currentColumns: TableColumnsType<Member>) {
const visible = currentColumns.flatMap<{ key: 'name' | 'city' | 'status'; title: unknown }>(
(column) =>
typeof column !== 'symbol' &&
column.visible !== false &&
(column.key === 'name' || column.key === 'city' || column.key === 'status')
? [{ key: column.key, title: column.title }]
: [],
)
if (!visible.length) return
const cell = (value: unknown) => `"${String(value ?? '').replace(/"/g, '""')}"`
csv.value = [
visible.map((column) => cell(column.title)).join(','),
...data.map((row) => visible.map((column) => cell(row[column.key])).join(',')),
].join('\r\n')
const url = URL.createObjectURL(
new Blob(['\uFEFF', csv.value], { type: 'text/csv;charset=utf-8;' }),
)
const link = document.createElement('a')
link.href = url
link.download = 'members.csv'
link.click()
setTimeout(() => URL.revokeObjectURL(url), 0)
}
</script>
<template>
<div class="toolbar-demo">
<VTable :columns="columns" :size="size" :data-source="rows" :loading="loading" bordered>
<template #title="{ data }">
<VTableToolbar
v-model:columns="columns"
v-model:size="size"
title="团队成员"
:loading="loading"
:options="{ fullScreen: true }"
@reload="reload"
>
<template #actions="{ columns: currentColumns, disabled }">
<Button :disabled="disabled" @click="exportCsv(data, currentColumns)">导出 CSV</Button>
</template>
</VTableToolbar>
</template>
</VTable>
<p aria-live="polite">已刷新 {{ refreshes }} 次</p>
<pre v-if="csv" class="toolbar-demo-csv" aria-label="导出内容">{{ csv }}</pre>
</div>
</template>
<style scoped>
.toolbar-demo-csv {
max-width: 100%;
overflow: auto;
}
</style>The component does not make data requests or convert export files. You can replace the export function in the example with Excel, PDF or a server-side export job; the button's permissions, confirmation and progress are up to the application.
Search, filtering and view switching
search enables a combined keyword input with a search icon button on its right, 32px high by default. When you only care about the submitted result, listening to search is enough: pressing Enter, clicking the search button or clicking the clear icon all trigger it, with the submitted keyword as the argument, which is an empty string on clear.
<VTableToolbar search @search="keyword = $event" />The input draft is held by the component by default, and input changes do not submit or reload automatically. When you need to read or modify the draft from outside (for example a "Reset" button that also clears the input), take it over with v-model:search-value; the input then always displays the value passed in.
The clear icon triggers update:searchValue(''), clearSearch and search('') in that order. Handle the request for an empty keyword in search; clearSearch only serves to tell the "clear" action apart, so do not send the request again in both events.
#filter holds the filter controls your application already has; by default it shares a row with the action buttons, and multipleLine moves it to a second row. #extra always takes a full row of its own and can combine Tabs, a selection alert or other application content. Whether the state, page number and selection reset when the view switches is up to the application.
<script setup lang="ts">
import { computed, ref } from 'vue'
import { Button, VTable, VTableToolbar } from '@vtable-guild/vtable-guild'
import type { TableColumnsType } from '@vtable-guild/vtable-guild'
interface Order {
key: number
name: string
status: 'pending' | 'done'
city: string
}
const columns: TableColumnsType<Order> = [
{ key: 'name', title: '姓名', dataIndex: 'name' },
{ key: 'city', title: '城市', dataIndex: 'city' },
{ key: 'status', title: '状态', dataIndex: 'status' },
]
const rows: Order[] = [
{ key: 1, name: '陈嘉', city: '杭州', status: 'pending' },
{ key: 2, name: '苏晚', city: '上海', status: 'done' },
{ key: 3, name: '周野', city: '杭州', status: 'pending' },
]
const submittedKeyword = ref('')
const view = ref<'all' | Order['status']>('all')
const city = ref('')
const refreshes = ref(0)
const filteredRows = computed(() =>
rows.filter(
(row) =>
(!submittedKeyword.value || row.name.includes(submittedKeyword.value)) &&
(view.value === 'all' || row.status === view.value) &&
(!city.value || row.city === city.value),
),
)
const views = [
{ key: 'all', label: '全部' },
{ key: 'pending', label: '待处理' },
{ key: 'done', label: '已完成' },
] as const
</script>
<template>
<VTable :columns="columns" :data-source="filteredRows">
<template #title>
<VTableToolbar
title="订单列表"
:search="{ placeholder: '按姓名查询' }"
:options="{ density: false, setting: false }"
multiple-line
@search="submittedKeyword = $event"
@reload="refreshes++"
>
<template #filter>
<label
>城市
<select v-model="city" aria-label="城市">
<option value="">全部城市</option>
<option value="杭州">杭州</option>
<option value="上海">上海</option>
</select></label
>
<span>刷新 {{ refreshes }} 次</span>
</template>
<template #extra>
<nav aria-label="订单视图" class="toolbar-search-views">
<Button
v-for="item in views"
:key="item.key"
:type="view === item.key ? 'primary' : 'default'"
:aria-pressed="view === item.key"
@click="view = item.key"
>{{ item.label }}</Button
>
</nav>
</template>
</VTableToolbar>
</template>
</VTable>
</template>
<style scoped>
.toolbar-search-views {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
</style>#search can replace the built-in search control entirely. It shares searchValue, updateSearchValue(value), submitSearch(value?) and clearSearch() with the other toolbar slots, and the draft can likewise be left unbound. During loading the search draft can still be modified while submitting and clearing are temporarily disabled; disabled disables both the input and the actions. Submitting with Enter skips the IME composition state.
<VTableToolbar @search="submitQuery">
<template #search="{ searchValue, updateSearchValue, submitSearch, disabled }">
<a-input-search
:value="searchValue"
:disabled="disabled"
@update:value="updateSearchValue"
@search="submitSearch"
/>
</template>
</VTableToolbar>Toggling and replacing
Hide an individual built-in tool through options; false turns off all built-in tools. #actions and #settings are kept, so application buttons can be used on their own.
<VTableToolbar
v-model:columns="columns"
v-model:size="size"
title="Orders"
:options="{ reload: false, density: false }"
>
<template #actions="{ disabled }">
<a-button :disabled="disabled" @click="exportOrders">Export Excel</a-button>
<a-button type="primary" :disabled="disabled" @click="createOrder">New order</a-button>
</template>
</VTableToolbar>#title customizes the title area. #settings replaces the built-in tools area entirely, which suits custom icons, action order or menus; the slot params provide the reload and toggleFullscreen methods and the current state.
<VTableToolbar title="Orders" :loading="loading" @reload="loadOrders">
<template #title><strong>Orders</strong><a-tag>This month</a-tag></template>
<template #settings="{ reload, loading, disabled }">
<a-button :loading="loading" :disabled="disabled" @click="reload">Reload</a-button>
</template>
</VTableToolbar>State
columnsandsizeare shared with the table and accept updates throughv-model. Withoutcolumns, column settings are hidden; withoutsize, the default density of the table theme is read.- Reload only triggers
reload. The application setsloadingduring the request; the reload button shows a loading state and prevents repeated clicks, while density and column settings remain usable. disableddisables the built-in actions. Custom buttons readdisabledandloadingfrom the slot params and decide their own disabling rules.
Fullscreen
When the toolbar is placed in the title or footer slot of VTable, enabling options.fullScreen is all it takes, and the whole table (including the title and pagination) enters browser fullscreen:
<VTable :columns="columns" :data-source="rows">
<template #title>
<VTableToolbar :options="{ fullScreen: true }" />
</template>
</VTable>When content outside the table, such as a query form, needs to go fullscreen together with it, or the toolbar is not inside a table slot, specify an element with fullscreenTarget; it takes precedence over the containing table:
<div ref="page">
<QueryForm />
<VTableToolbar :options="{ fullScreen: true }" :fullscreen-target="() => page" />
<VTable :columns="columns" :data-source="rows" />
</div>- A fullscreen table uses
--vtg-table-bgas its background and scrolls when the content exceeds the screen. The background, padding and scrolling of a custom target are set by the application through:fullscreen. - The button is disabled when there is no usable target or the browser does not support fullscreen; when the toolbar is neither inside a table nor given a
fullscreenTarget, a warning is issued in development. fullscreenChangefires after the browser confirms the change, and exiting with Escape is synced too;fullscreenErrorfires when the request is rejected.- In fullscreen, the filter menu, column settings, page size menu and tooltips are mounted inside the fullscreen element by default. When you customize the container through
getPopupContainer, it should return a descendant of the fullscreen element.
API
TRecord is the application row type.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
title | VNodeChild | - | Title; the #title slot can be used instead. |
columns | TableColumnsType<TRecord> | - | Controlled column config shared with the table; use with v-model:columns. Column settings are hidden when omitted. |
size | 'large' | 'middle' | 'small' | follows table theme | Density shared with the table; use with v-model:size. |
options | false | TableToolbarOptions | - | Built-in tool switches; see the options. false turns off all built-in tools. |
loading | boolean | false | Loading state of the reload button; reload, search submission and clearing are disabled meanwhile. |
search | boolean | TableToolbarSearchConfig | false | Enable the built-in search; see the options. |
searchValue | string | - | Search input draft. Controlled when passed, use with v-model:search-value; held by the component when omitted. |
multipleLine | boolean | false | Move the filter slot to its own row. |
disabled | boolean | false | Disable built-in actions and pass the disabled state to slots. |
fullscreenTarget | () => HTMLElement | null | undefined | enclosing table | Element that enters full screen; defaults to the root element of the enclosing table. Pass it when the toolbar is outside the table's title / footer slots, or when content outside the table should be included. |
columnSettings | object | - | Config for the embedded column settings panel; see the options. |
locale | object | - | Per-instance text overrides; fields are listed in Themes and locales. |
ui | object | - | Per-instance slot class overrides; available slots are listed in ui slots. |
class | string | - | Class for the root element. |
options
Switches for the built-in tools. fixed and draggable are passed to the column settings panel.
| Field | Type | Default | Description |
|---|---|---|---|
reload | boolean | true | Show the reload button. |
density | boolean | true | Show the density switch. |
setting | boolean | true | Show the column settings entry; hidden when columns is not passed. |
fixed | boolean | true | Pin buttons in the column settings panel. |
draggable | boolean | true | Drag reordering in the column settings panel. |
fullScreen | boolean | false | Show the full screen button. For the full screen target, see fullscreenTarget. |
search
The configuration fields when search is an object; passing true uses the defaults.
| Field | Type | Default | Description |
|---|---|---|---|
placeholder | string | follows locale | Placeholder and accessible name of the input; defaults to searchPlaceholder from the locale. |
clearable | boolean | true | Show the clear icon when the input has content. |
columnSettings
The configuration passed to the embedded column settings panel; the fields mean the same as the props of the same name on VTableColumnSettings.
| Field | Type | Default | Description |
|---|---|---|---|
locale | object | - | Text overrides for the column settings panel. |
ui | object | - | Slot class overrides for the column settings panel; available slots are listed in ui slots. |
class | string | - | Class for the container of the column settings triggers. |
getPopupContainer | (trigger: HTMLElement) => HTMLElement | - | Mount container for the density menu and the column settings panel, document.body by default. In browser full screen they mount inside the full screen element by default; a custom function should return one of its descendants. |
Events
| Event | Payload | Description |
|---|---|---|
update:columns | (columns: TableColumnsType<TRecord>) => void | Column visibility, pinning or order changed. |
update:size | (size: 'large' | 'middle' | 'small') => void | Density changed. |
reset | () => void | "Reset" was clicked in the column settings panel; only the initial column visibility is restored. |
reload | () => void | Reload was clicked. The component does not issue a request. |
update:searchValue | (value: string) => void | The search input draft changed; this is not a submission. |
search | (value: string) => void | Search submitted by pressing Enter or clicking the search button or the clear icon. value is an empty string when clearing. |
clearSearch | () => void | The clear icon was clicked; search is emitted next with an empty string. |
fullscreenChange | (active: boolean) => void | Emitted after the browser confirms entering or leaving full screen, including leaving with Escape. |
fullscreenError | (error: unknown) => void | The browser rejected the full screen request. |
Slots
| Slot | Payload type | Description |
|---|---|---|
title | TableToolbarSlotProps<TRecord> | Custom title area. |
actions | TableToolbarSlotProps<TRecord> | Application action buttons, next to the built-in tools. |
settings | TableToolbarSlotProps<TRecord> | Replaces the built-in tools area entirely. |
search | TableToolbarSlotProps<TRecord> | Replaces the built-in search control. |
filter | TableToolbarSlotProps<TRecord> | Filter controls; on the same row as the actions by default, on their own row with multipleLine. |
extra | TableToolbarSlotProps<TRecord> | Extra content on a full row of its own. |
columnLabel | { column: ColumnType<TRecord> | ColumnGroupType<TRecord> } | Custom column labels in the column settings panel. |
Slot Props
Every slot except columnLabel receives TableToolbarSlotProps<TRecord>.
| Field | Type | Description |
|---|---|---|
columns | TableColumnsType<TRecord> | Current column config; an empty array when columns is not passed. |
size | 'large' | 'middle' | 'small' | Current density. |
loading | boolean | Current loading state. |
disabled | boolean | Current disabled state. |
fullscreen | boolean | Whether the full screen target is in full screen. |
fullscreenAvailable | boolean | A full screen target exists and the browser supports full screen. |
reload | () => void | Emits the reload event; does nothing while disabled or loading. |
toggleFullscreen | () => Promise<void> | Enter or leave full screen. |
searchValue | string | Current search draft. |
updateSearchValue | (value: string) => void | Update the search draft. |
submitSearch | (value?: string) => void | Submit the search; uses the current draft when no argument is passed. |
clearSearch | () => void | Clear the draft and submit an empty keyword. |
Themes and locales
The toolbar uses the global theme.toolbar.slots or the per-instance ui; the embedded column settings are overridden through theme.columnSettings.slots or columnSettings.ui.
Toolbar text follows the global locale and supports localeOverrides.toolbar and the per-instance locale. Column settings text is still controlled by columnSettings.locale or localeOverrides.columnSettings.
The theme code lists the default classes of the toolbar and of the column settings panel separately.
ui slots
| Theme config | Slot | Description |
|---|---|---|
theme.toolbar | root | Toolbar root container and responsive layout. |
theme.toolbar | title | Title area. |
theme.toolbar | right | Wrapper around application actions and built-in tools. |
theme.toolbar | actions | Container for #actions application buttons. |
theme.toolbar | settings | Container for built-in tools or #settings. |
theme.toolbar | search | Toolbar lightweight search container. |
theme.toolbar | searchGroup | Combined container for the search input area and the submit button. |
theme.toolbar | searchField | Outer layer of the search text box. |
theme.toolbar | searchInput | Search text input. |
theme.toolbar | searchSubmit | Search submit button. |
theme.toolbar | searchClear | Button that clears the search text. |
theme.toolbar | searchIcon | Search and clear icons. |
theme.toolbar | filter | Container for #filter content in the single-row layout. |
theme.toolbar | extra | Container for #extra content, and for #filter content in the multi-row layout. |
theme.toolbar | action | Built-in buttons such as refresh and fullscreen. |
theme.toolbar | icon | Built-in tool icon. |
theme.toolbar | loadingIcon | Refresh loading animation. |
theme.columnSettings | root | Container for the density and column settings triggers. |
theme.columnSettings | trigger | Column settings button. |
theme.columnSettings | densityTrigger | Density button. |
theme.columnSettings | popup | Column settings overlay. |
theme.columnSettings | densityPopup | Density overlay. |
theme.columnSettings | density | Density menu option. |
theme.columnSettings | header | Column settings panel header. |
theme.columnSettings | heading | Select-all heading. |
theme.columnSettings | reset | Reset button. |
theme.columnSettings | columns | Column list. |
theme.columnSettings | children | Nested child column list. |
theme.columnSettings | item | Column list item. |
theme.columnSettings | row | Column option row; serves as the drag carrier. |
theme.columnSettings | rowDragging | Outline of the source row being dragged. |
theme.columnSettings | rowDropAbove | Insertion line above the target row. |
theme.columnSettings | rowDropBelow | Insertion line below the target row. |
theme.columnSettings | rowDropDot | Dot at the left end of the insertion line. |
theme.columnSettings | dragHandle | Drag handle. |
theme.columnSettings | pinActions | Pin position button group. |
theme.columnSettings | pinAction | Pin position button. |
theme.columnSettings | pinIcon | Pin position icon. |
theme.columnSettings | group | Container for a group of columns divided by pin position. |
theme.columnSettings | groupTitle | Pin position group title. |
theme.columnSettings | groupColumns | Column list within a group. |
theme.columnSettings | label | Column option label. |
theme.columnSettings | checkboxControl | Checkbox container. |
theme.columnSettings | checkbox | Checkbox input element. |
theme.columnSettings | checkMark | Check mark. |
theme.columnSettings | indeterminateMark | Indeterminate mark. |
theme.columnSettings | labelText | Column option label text. |
theme.columnSettings | empty | Message shown when there are no configurable columns. |
Preset defaults
createVTableGuild({
theme: {
toolbar: {
slots: {
root: 'flex min-h-8 flex-wrap items-center justify-between gap-x-4 gap-y-3 text-[length:var(--vtg-table-font-size)] text-[color:var(--color-on-surface)] font-[family-name:var(--font-family-base)] leading-[var(--vtg-table-line-height)]',
title: 'min-w-0 flex-1 text-[length:var(--vtg-toolbar-title-font-size)] font-[number:var(--vtg-toolbar-title-font-weight)]',
right: 'ml-auto flex max-w-full flex-wrap items-center justify-end gap-4',
actions: 'flex max-w-full flex-wrap items-center gap-2',
settings: 'inline-flex shrink-0 items-center gap-4',
search: 'flex w-[var(--vtg-toolbar-search-width,240px)] max-w-full items-center',
searchGroup: 'inline-flex h-[var(--vtg-toolbar-search-height,32px)] w-full min-w-0 items-stretch text-[length:var(--vtg-toolbar-search-font-size,14px)]',
searchField: 'relative z-0 -mr-px flex min-w-0 flex-1 items-center gap-1 rounded-l-[var(--vtg-input-border-radius)] border border-[color:var(--color-border)] bg-[color:var(--color-surface)] px-[var(--vtg-input-padding-inline)] transition-all duration-200 hover:z-10 hover:border-[color:var(--color-primary-hover)] focus-within:z-10 focus-within:border-[color:var(--color-primary)] focus-within:shadow-[0_0_0_2px_rgba(5,145,255,0.1)] data-[disabled]:cursor-not-allowed data-[disabled]:bg-[color:var(--color-bg-disabled)] data-[disabled]:hover:border-[color:var(--color-border)]',
searchInput: 'h-full min-w-0 flex-1 rounded-none border-0 bg-transparent p-0 text-[length:var(--vtg-toolbar-search-font-size,14px)] outline-none shadow-none focus:shadow-none',
searchSubmit: 'relative z-0 inline-flex w-[var(--vtg-toolbar-search-height,32px)] shrink-0 items-center justify-center rounded-r-[var(--vtg-input-border-radius)] border border-[color:var(--color-border)] bg-[color:var(--color-surface)] p-0 text-[color:var(--color-on-surface)] cursor-pointer transition-colors duration-200 hover:z-10 hover:text-[color:var(--color-primary-hover)] hover:border-[color:var(--color-primary-hover)] focus-visible:z-10 focus-visible:outline-none focus-visible:border-[color:var(--color-primary)] focus-visible:shadow-[0_0_0_2px_rgba(5,145,255,0.1)] disabled:cursor-not-allowed disabled:bg-[color:var(--color-bg-disabled)] disabled:text-[color:var(--color-text-disabled)] disabled:hover:border-[color:var(--color-border)]',
searchClear: 'inline-flex shrink-0 items-center justify-center border-0 bg-transparent p-0 text-[color:var(--color-text-placeholder)] cursor-pointer hover:text-[color:var(--color-muted)] disabled:cursor-not-allowed disabled:text-[color:var(--color-text-disabled)]',
searchIcon: 'block h-[1em] w-[1em] shrink-0',
filter: 'flex min-w-0 max-w-full flex-wrap items-center gap-2',
extra: 'flex w-full min-w-0 flex-wrap items-center gap-3',
action: 'inline-flex items-center justify-center h-6 w-6 p-0 border-0 bg-transparent text-[length:var(--vtg-column-settings-icon-size)] text-[color:var(--color-on-surface)] cursor-pointer transition-colors duration-200 hover:text-[color:var(--color-primary)] disabled:cursor-not-allowed disabled:text-[color:var(--color-text-disabled)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)]',
icon: 'block',
loadingIcon: 'animate-spin motion-reduce:animate-none',
},
},
columnSettings: {
slots: {
root: 'inline-flex items-center gap-4',
trigger: 'inline-flex items-center justify-center h-6 w-6 p-0 border-0 bg-transparent text-[length:var(--vtg-column-settings-icon-size)] text-[color:var(--color-on-surface)] cursor-pointer transition-colors duration-200 hover:text-[color:var(--color-primary)] disabled:cursor-not-allowed disabled:text-[color:var(--color-text-disabled)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)]',
densityTrigger: 'inline-flex items-center justify-center h-6 w-6 p-0 border-0 bg-transparent text-[length:var(--vtg-column-settings-icon-size)] text-[color:var(--color-on-surface)] cursor-pointer transition-colors duration-200 hover:text-[color:var(--color-primary)] disabled:cursor-not-allowed disabled:text-[color:var(--color-text-disabled)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)]',
popup: '[--vtg-table-popup-panel-radius:var(--vtg-column-settings-radius)] [--vtg-table-popup-panel-shadow:var(--vtg-column-settings-shadow)] flex flex-col [--vtg-table-popup-width:var(--vtg-column-settings-width)] max-w-[calc(100vw-16px)]',
densityPopup: '[--vtg-table-popup-panel-radius:var(--vtg-column-settings-radius)] [--vtg-table-popup-panel-shadow:var(--vtg-column-settings-shadow)] min-w-[80px]',
density: 'block w-full border-0 rounded-[var(--vtg-btn-border-radius-sm)] px-3 py-[5px] text-left text-[length:var(--vtg-table-font-size)] font-normal leading-[var(--vtg-table-line-height)] bg-transparent cursor-pointer hover:bg-[color:var(--color-control-item-hover-bg)] aria-checked:bg-[color:var(--color-control-item-active-bg)] aria-checked:text-[color:var(--color-primary)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)]',
header: 'flex items-center justify-between gap-3 h-8 mb-2 px-2',
heading: 'group inline-flex items-center gap-2 cursor-pointer font-normal',
reset: 'shrink-0 border-0 bg-transparent p-0 text-[color:var(--color-primary)] text-[length:var(--vtg-table-font-size)] font-semibold cursor-pointer hover:text-[color:var(--color-primary-hover)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)]',
columns: 'm-0 max-h-[280px] overflow-auto list-none px-2 py-2',
children: 'm-0 list-none pl-6',
item: 'm-0 p-0 pb-1',
row: 'relative flex min-w-0 items-center gap-1 select-none [&[draggable=true]]:cursor-grab [&[draggable=true]]:active:cursor-grabbing [&[draggable=false]]:cursor-not-allowed',
rowDragging: 'rounded-[var(--vtg-btn-border-radius-sm)] bg-[color:var(--color-control-item-active-bg)] ring-1 ring-inset ring-[color:var(--color-primary)]',
rowDropAbove: 'pointer-events-none absolute right-0 top-0 z-[1] h-[2px] rounded-[1px] left-[calc(var(--vtg-column-settings-icon-size)+var(--vtg-checkbox-size)+16px)] bg-[color:var(--vtg-table-row-drop-indicator-color)]',
rowDropBelow: 'pointer-events-none absolute right-0 bottom-0 z-[1] h-[2px] rounded-[1px] left-[calc(var(--vtg-column-settings-icon-size)+var(--vtg-checkbox-size)+16px)] bg-[color:var(--vtg-table-row-drop-indicator-color)]',
rowDropDot: 'pointer-events-none absolute start-[-6px] top-[-3px] h-2 w-2 rounded-full border-2 border-[color:var(--vtg-table-row-drop-indicator-color)] bg-transparent',
dragHandle: 'inline-flex w-[var(--vtg-column-settings-icon-size)] shrink-0 items-center justify-center mr-2 select-none text-[color:var(--color-muted)]',
pinActions: 'inline-flex shrink-0 items-center gap-0.5',
pinAction: 'inline-flex items-center justify-center h-5 w-5 p-0 border-0 rounded-[var(--vtg-btn-border-radius-sm)] bg-transparent text-[color:var(--color-muted)] cursor-pointer hover:text-[color:var(--color-primary)] hover:bg-[color:var(--color-control-item-hover-bg)] aria-pressed:text-[color:var(--color-primary)] disabled:cursor-not-allowed disabled:text-[color:var(--color-text-disabled)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)]',
pinIcon: 'h-[var(--vtg-column-settings-pin-icon-size,14px)] w-[var(--vtg-column-settings-pin-icon-size,14px)]',
group: 'm-0 list-none p-0',
groupTitle: 'py-1 text-[length:var(--vtg-table-font-size)] text-[color:var(--color-muted)]',
groupColumns: 'm-0 list-none p-0',
label: 'group flex min-w-0 flex-1 min-h-6 items-center gap-1 cursor-pointer has-[:disabled]:cursor-not-allowed has-[:disabled]:text-[color:var(--color-text-disabled)]',
checkboxControl: 'relative inline-flex shrink-0 h-[var(--vtg-checkbox-size)] w-[var(--vtg-checkbox-size)]',
checkbox: 'peer m-0 h-full w-full appearance-none border border-[color:var(--color-border)] rounded-[var(--vtg-checkbox-border-radius)] bg-[color:var(--color-surface)] cursor-inherit transition-colors duration-300 checked:bg-[color:var(--color-primary)] checked:border-[color:var(--color-primary)] group-hover:enabled:border-[color:var(--color-primary)] group-hover:enabled:checked:bg-[color:var(--color-primary-hover)] group-hover:enabled:checked:border-transparent disabled:bg-[color:var(--color-bg-disabled)] disabled:border-[color:var(--color-border)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)]',
checkMark: 'pointer-events-none absolute box-border top-1/2 left-[22%] w-[5.71px] h-[9.14px] border-b-2 border-r-2 border-[color:var(--vtg-checkbox-check-color,#fff)] [transform:rotate(45deg)_translate(-50%,_-50%)] peer-disabled:border-[color:var(--color-text-disabled)]',
indeterminateMark: 'pointer-events-none absolute top-1/2 left-1/2 w-2 h-2 rounded-[1px] bg-[color:var(--vtg-checkbox-indeterminate-color,var(--color-primary))] -translate-x-1/2 -translate-y-1/2',
labelText: 'min-w-0 flex-1 truncate px-1',
empty: 'px-2 py-2 text-[color:var(--color-muted)]',
},
},
},
})createVTableGuild({
themePreset: 'element-plus',
theme: {
toolbar: {
slots: {
root: 'flex min-h-8 flex-wrap items-center justify-between gap-x-4 gap-y-3 text-[length:var(--vtg-table-font-size)] text-[color:var(--color-on-surface)] font-[family-name:var(--font-family-base)] leading-[var(--vtg-table-line-height)]',
title: 'min-w-0 flex-1 text-[length:var(--vtg-toolbar-title-font-size)] font-[number:var(--vtg-toolbar-title-font-weight)]',
right: 'ml-auto flex max-w-full flex-wrap items-center justify-end gap-4',
actions: 'flex max-w-full flex-wrap items-center gap-2 [&>.el-button+.el-button]:!ml-0',
settings: 'inline-flex shrink-0 items-center gap-4',
search: 'flex w-[var(--vtg-toolbar-search-width,240px)] max-w-full items-center',
searchGroup: 'inline-flex h-[var(--vtg-toolbar-search-height,32px)] w-full min-w-0 items-stretch text-[length:var(--vtg-toolbar-search-font-size,14px)]',
searchField: 'relative z-0 -mr-px flex min-w-0 flex-1 items-center gap-1 rounded-l-[var(--vtg-input-border-radius)] border border-[color:var(--color-border)] bg-[color:var(--color-surface)] px-[var(--vtg-input-padding-inline)] transition-all duration-200 hover:z-10 hover:border-[color:var(--color-primary-hover)] focus-within:z-10 focus-within:border-[color:var(--color-primary)] focus-within:shadow-[0_0_0_2px_rgba(5,145,255,0.1)] data-[disabled]:cursor-not-allowed data-[disabled]:bg-[color:var(--color-bg-disabled)] data-[disabled]:hover:border-[color:var(--color-border)] hover:border-[color:var(--color-border-hover)] focus-within:shadow-none focus-within:hover:border-[color:var(--color-primary)]',
searchInput: 'h-full min-w-0 flex-1 rounded-none border-0 bg-transparent p-0 text-[length:var(--vtg-toolbar-search-font-size,14px)] outline-none shadow-none focus:shadow-none',
searchSubmit: 'relative z-0 inline-flex w-[var(--vtg-toolbar-search-height,32px)] shrink-0 items-center justify-center rounded-r-[var(--vtg-input-border-radius)] border border-[color:var(--color-border)] bg-[color:var(--color-surface)] p-0 text-[color:var(--color-on-surface)] cursor-pointer transition-colors duration-200 hover:z-10 hover:text-[color:var(--color-primary-hover)] hover:border-[color:var(--color-primary-hover)] focus-visible:z-10 focus-visible:outline-none focus-visible:border-[color:var(--color-primary)] focus-visible:shadow-[0_0_0_2px_rgba(5,145,255,0.1)] disabled:cursor-not-allowed disabled:bg-[color:var(--color-bg-disabled)] disabled:text-[color:var(--color-text-disabled)] disabled:hover:border-[color:var(--color-border)] bg-[color:var(--color-bg-disabled)] text-[color:var(--color-muted)] focus-visible:shadow-none',
searchClear: 'inline-flex shrink-0 items-center justify-center border-0 bg-transparent p-0 text-[color:var(--color-text-placeholder)] cursor-pointer hover:text-[color:var(--color-muted)] disabled:cursor-not-allowed disabled:text-[color:var(--color-text-disabled)]',
searchIcon: 'block h-[1em] w-[1em] shrink-0',
filter: 'flex min-w-0 max-w-full flex-wrap items-center gap-2',
extra: 'flex w-full min-w-0 flex-wrap items-center gap-3',
action: 'inline-flex items-center justify-center h-6 w-6 p-0 border-0 bg-transparent text-[length:var(--vtg-column-settings-icon-size)] text-[color:var(--color-on-surface)] cursor-pointer transition-colors duration-200 hover:text-[color:var(--color-primary)] disabled:cursor-not-allowed disabled:text-[color:var(--color-text-disabled)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)]',
icon: 'block',
loadingIcon: 'animate-spin motion-reduce:animate-none',
},
},
columnSettings: {
slots: {
root: 'inline-flex items-center gap-4',
trigger: 'inline-flex items-center justify-center h-6 w-6 p-0 border-0 bg-transparent text-[length:var(--vtg-column-settings-icon-size)] text-[color:var(--color-on-surface)] cursor-pointer transition-colors duration-200 hover:text-[color:var(--color-primary)] disabled:cursor-not-allowed disabled:text-[color:var(--color-text-disabled)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)]',
densityTrigger: 'inline-flex items-center justify-center h-6 w-6 p-0 border-0 bg-transparent text-[length:var(--vtg-column-settings-icon-size)] text-[color:var(--color-on-surface)] cursor-pointer transition-colors duration-200 hover:text-[color:var(--color-primary)] disabled:cursor-not-allowed disabled:text-[color:var(--color-text-disabled)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)]',
popup: '[--vtg-table-popup-panel-radius:var(--vtg-column-settings-radius)] [--vtg-table-popup-panel-shadow:var(--vtg-column-settings-shadow)] flex flex-col [--vtg-table-popup-width:var(--vtg-column-settings-width)] max-w-[calc(100vw-16px)]',
densityPopup: '[--vtg-table-popup-panel-radius:var(--vtg-column-settings-radius)] [--vtg-table-popup-panel-shadow:var(--vtg-column-settings-shadow)] min-w-[80px]',
density: 'block w-full border-0 rounded-[var(--vtg-btn-border-radius-sm)] px-3 py-[5px] text-left text-[length:var(--vtg-table-font-size)] font-normal leading-[var(--vtg-table-line-height)] bg-transparent cursor-pointer hover:bg-[color:var(--color-control-item-hover-bg)] aria-checked:bg-[color:var(--color-control-item-active-bg)] aria-checked:text-[color:var(--color-primary)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)]',
header: 'flex items-center justify-between gap-3 h-8 mb-2 px-2',
heading: 'group inline-flex items-center gap-2 cursor-pointer font-normal',
reset: 'shrink-0 border-0 bg-transparent p-0 text-[color:var(--color-primary)] text-[length:var(--vtg-table-font-size)] font-semibold cursor-pointer hover:text-[color:var(--color-primary-hover)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)]',
columns: 'm-0 max-h-[280px] overflow-auto list-none px-2 py-2',
children: 'm-0 list-none pl-6',
item: 'm-0 p-0 pb-1',
row: 'relative flex min-w-0 items-center gap-1 select-none [&[draggable=true]]:cursor-grab [&[draggable=true]]:active:cursor-grabbing [&[draggable=false]]:cursor-not-allowed',
rowDragging: 'rounded-[var(--vtg-btn-border-radius-sm)] bg-[color:var(--color-control-item-active-bg)] ring-1 ring-inset ring-[color:var(--color-primary)]',
rowDropAbove: 'pointer-events-none absolute right-0 top-0 z-[1] h-[2px] rounded-[1px] left-[calc(var(--vtg-column-settings-icon-size)+var(--vtg-checkbox-size)+16px)] bg-[color:var(--vtg-table-row-drop-indicator-color)]',
rowDropBelow: 'pointer-events-none absolute right-0 bottom-0 z-[1] h-[2px] rounded-[1px] left-[calc(var(--vtg-column-settings-icon-size)+var(--vtg-checkbox-size)+16px)] bg-[color:var(--vtg-table-row-drop-indicator-color)]',
rowDropDot: 'pointer-events-none absolute start-[-6px] top-[-3px] h-2 w-2 rounded-full border-2 border-[color:var(--vtg-table-row-drop-indicator-color)] bg-transparent',
dragHandle: 'inline-flex w-[var(--vtg-column-settings-icon-size)] shrink-0 items-center justify-center mr-2 select-none text-[color:var(--color-muted)]',
pinActions: 'inline-flex shrink-0 items-center gap-0.5',
pinAction: 'inline-flex items-center justify-center h-5 w-5 p-0 border-0 rounded-[var(--vtg-btn-border-radius-sm)] bg-transparent text-[color:var(--color-muted)] cursor-pointer hover:text-[color:var(--color-primary)] hover:bg-[color:var(--color-control-item-hover-bg)] aria-pressed:text-[color:var(--color-primary)] disabled:cursor-not-allowed disabled:text-[color:var(--color-text-disabled)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)]',
pinIcon: 'h-[var(--vtg-column-settings-pin-icon-size,14px)] w-[var(--vtg-column-settings-pin-icon-size,14px)]',
group: 'm-0 list-none p-0',
groupTitle: 'py-1 text-[length:var(--vtg-table-font-size)] text-[color:var(--color-muted)]',
groupColumns: 'm-0 list-none p-0',
label: 'group flex min-w-0 flex-1 min-h-6 items-center gap-1 cursor-pointer has-[:disabled]:cursor-not-allowed has-[:disabled]:text-[color:var(--color-text-disabled)]',
checkboxControl: 'relative inline-flex shrink-0 h-[var(--vtg-checkbox-size)] w-[var(--vtg-checkbox-size)]',
checkbox: 'peer m-0 h-full w-full appearance-none border border-[color:var(--color-border)] rounded-[var(--vtg-checkbox-border-radius)] bg-[color:var(--color-surface)] cursor-inherit transition-colors duration-300 checked:bg-[color:var(--color-primary)] checked:border-[color:var(--color-primary)] group-hover:enabled:border-[color:var(--color-primary)] group-hover:enabled:checked:bg-[color:var(--color-primary-hover)] group-hover:enabled:checked:border-transparent disabled:bg-[color:var(--color-bg-disabled)] disabled:border-[color:var(--color-border)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)] indeterminate:bg-[color:var(--color-primary)] indeterminate:border-[color:var(--color-primary)]',
checkMark: 'pointer-events-none absolute box-content top-1/2 left-1/2 w-[3px] h-[7px] border border-transparent border-l-0 border-t-0 border-[color:var(--vtg-checkbox-check-color,#fff)] [transform:translate(-45%,_-60%)_rotate(45deg)] [transform-origin:center] peer-disabled:border-[color:var(--color-text-placeholder)]',
indeterminateMark: 'pointer-events-none absolute left-0 right-0 top-[5px] w-[12px] rounded-none translate-x-0 translate-y-0 h-[2px] bg-[color:var(--vtg-checkbox-indeterminate-color,#fff)] [transform:scale(.5)]',
labelText: 'min-w-0 flex-1 truncate px-1',
empty: 'px-2 py-2 text-[color:var(--color-muted)]',
},
},
},
})CSS variables
| Variable | Purpose | antdv | element-plus |
|---|---|---|---|
--vtg-table-popup-radius | Radius of table popups such as filtering and batch selection | 6px | 2px |
--vtg-table-popup-border | Table popup border | 0 | 1px solid var(--vtg-border-color-lighter, var(--color-default)) |
--vtg-table-popup-padding-block | Table popup vertical padding | 4px | 5px |
--vtg-table-popup-padding-inline | Table popup horizontal padding | 4px | 0px |
--vtg-table-popup-shadow | Table popup shadow | 0 6px 16px rgb(0 0 0 / 8%), 0 3px 6px -4px rgb(0 0 0 / 12%), 0 9px 28px 8px rgb(0 0 0 / 5%) | 0 0 12px rgb(0 0 0 / 12%) |
--vtg-toolbar-title-font-size | Toolbar title font size | 16px | 16px |
--vtg-toolbar-title-font-weight | Toolbar title font weight | 500 | 500 |
--vtg-toolbar-search-width | Toolbar lightweight search width | 240px | 240px |
--vtg-toolbar-search-height | Toolbar lightweight search height | 32px | 32px |
--vtg-toolbar-search-font-size | Toolbar lightweight search font size | 14px | 14px |
--vtg-column-settings-width | Column settings panel width | 224px | 280px |
--vtg-column-settings-radius | Radius of the column settings and density overlays | var(--vtg-table-popup-radius) | var(--vtg-table-popup-radius) |
--vtg-column-settings-icon-size | Icon size of the toolbar and column settings | 16px | 16px |
--vtg-column-settings-z | z-index of the column settings and density overlays | 1050 | 2000 |
--vtg-column-settings-shadow | Overlay shadow | var(--vtg-table-popup-shadow) | var(--vtg-table-popup-shadow) |
--vtg-column-settings-pin-icon-size | Icon size of the pin position buttons | undeclared, falls back to 14px | undeclared, falls back to 14px |
Type Declarations
Toolbar types
import type { VNodeChild } from 'vue'
import type {
TableColumnsType,
TableColumnSettingsProps,
TableColumnSettingsOptions,
TableColumnSettingsSize,
TableColumnSettingsSlots,
SlotProps,
ToolbarThemeConfig,
VTableGuildToolbarLocale,
} from '@vtable-guild/vtable-guild'
export interface TableToolbarOptions extends TableColumnSettingsOptions {
reload?: boolean
fullScreen?: boolean
}
export interface TableToolbarSearchConfig {
placeholder?: string
clearable?: boolean
}
export interface TableToolbarProps<TRecord extends object = Record<string, unknown>> {
title?: VNodeChild
columns?: TableColumnsType<TRecord>
size?: TableColumnSettingsSize
options?: false | TableToolbarOptions
loading?: boolean
search?: boolean | TableToolbarSearchConfig
searchValue?: string
multipleLine?: boolean
disabled?: boolean
fullscreenTarget?: () => HTMLElement | null | undefined
columnSettings?: Pick<
TableColumnSettingsProps<TRecord>,
'locale' | 'ui' | 'class' | 'getPopupContainer'
>
locale?: Partial<VTableGuildToolbarLocale>
ui?: SlotProps<ToolbarThemeConfig>
class?: string
}
export interface TableToolbarSlotProps<TRecord extends object = Record<string, unknown>> {
columns: TableColumnsType<TRecord>
size: TableColumnSettingsSize
loading: boolean
disabled: boolean
fullscreen: boolean
fullscreenAvailable: boolean
reload: () => void
toggleFullscreen: () => Promise<void>
searchValue: string
updateSearchValue: (value: string) => void
submitSearch: (value?: string) => void
clearSearch: () => void
}
export interface TableToolbarSlots<TRecord extends object = Record<string, unknown>> {
title?: (props: TableToolbarSlotProps<TRecord>) => VNodeChild
actions?: (props: TableToolbarSlotProps<TRecord>) => VNodeChild
settings?: (props: TableToolbarSlotProps<TRecord>) => VNodeChild
search?: (props: TableToolbarSlotProps<TRecord>) => VNodeChild
filter?: (props: TableToolbarSlotProps<TRecord>) => VNodeChild
extra?: (props: TableToolbarSlotProps<TRecord>) => VNodeChild
columnLabel?: TableColumnSettingsSlots<TRecord>['columnLabel']
}export interface TableColumnSettingsOptions {
density?: boolean
setting?: boolean
fixed?: boolean
draggable?: boolean
}export interface VTableGuildToolbarLocale {
searchPlaceholder?: string
search?: string
clearSearch?: string
label: string
reload: string
fullScreen: string
exitFullScreen: string
}export type ToolbarThemeConfig = typeof toolbarTheme
export type ToolbarSlots = keyof ToolbarThemeConfig['slots']