Column display and order
VTableColumnSettings gives a table column visibility, fixing, drag sorting and density switching. The panel and the table bind to the same columns and size: the panel only emits updates, and your application owns the applied state.
Column settings panel
v-model:columns receives the new columns array; v-model:size receives 'large' | 'middle' | 'small' and follows the table theme's default density when omitted. Both must also be passed to the table to take effect. The panel can go in the table's title slot or in an external toolbar; when you need a title, export, reload and fullscreen, use VTableToolbar.
The panel only adjusts top-level columns: dragging reorders within the same fixed region, the fix buttons move a column across regions, and a group moves as a whole. The order is written straight back to columns, so do not also pass columnOrder to the table, or it overrides the panel's order. "Reset" only restores visibility; to restore order and fixing as well, use useColumnState().reset().
Column configuration
- Give columns and groups a stable
keythat is unique among siblings; when omitted,dataIndexand then the position are used. After columns without a stable identity are reordered, a reset may map to the wrong column. - A function
titleis not called by the panel, which showskey/dataIndexby default; provide a label through#columnLabel="{ column }". hideInSetting: truekeeps a column and its children out of the panel and out of select-all and reset, without affecting how the table displays them.disable: truelocks visibility, fixing and order; the object form lockscheckbox,fixedandorderseparately. A column with a locked order is a drag boundary that other columns cannot cross.
More behavior details
- When a group is hidden, its children are temporarily disabled and keep their own visibility state; when a group contains a child with locked visibility, the whole group cannot be hidden. The panel allows hiding every application column.
- Fixing a group syncs all of its leaf columns; when a child forbids fixing, the whole group cannot be fixed. Fixed columns move to the corresponding end.
EXPAND_COLUMN/SELECTION_COLUMNdo not appear in the panel and keep their positions.- Checked means
visible !== false; a column withresponsivemay still be hidden at the current breakpoint. - The reset baseline is the visibility the panel first received, so preferences loaded before the panel mounts also become the baseline. Dynamically added columns use their state when they first appear, and removed columns are not added back. To rebuild the baseline, change the panel's Vue
keyto remount it. - Column width, sorting and filtering are not affected by panel actions.
- Buttons and checkboxes can be operated with the keyboard; Escape closes the panel and returns to the trigger, and tabbing out of the panel closes it.
Changes not taking effect?
| Symptom | Cause | Fix |
|---|---|---|
| After switching density, neither the selected item nor the row height changes | Density is controlled and size is not bound | Use v-model:size on the panel and pass the same value to the table's size |
| After checking, fixing or dragging, the panel does not change | The columns update emitted by the panel is not received | Use v-model:columns on the panel and pass the same columns to the table |
| After dragging, the panel order changes but the table order does not | columnOrder is passed as well and overrides the order of columns | Remove columnOrder and write the initial order in columns |
| After fixing, nothing is visible while scrolling | The table does not scroll horizontally | Make scroll.x larger than the container width, or shrink the container and look again |
| After clicking "Reset", order and fixing are not restored | "Reset" only restores visibility | Use useColumnState().reset() |
Panel API
Props, events and slots of VTableColumnSettings. TRecord is the application row type.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
columns | TableColumnsType<TRecord> | Required | Controlled column config; use with v-model:columns and pass the same columns to the table. |
size | 'large' | 'middle' | 'small' | follows table theme | Density shared with the table; use with v-model:size. |
disabled | boolean | false | Disable the entries and close any open panel. |
options | TableColumnSettingsOptions | - | Entry and action switches; see the options. |
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. |
locale | object | - | Per-instance text overrides; follows the global locale by default. |
ui | object | - | Per-instance slot class overrides; available slots are listed in Theming. |
class | string | - | Class for the root element. |
options
| Field | Type | Default | Description |
|---|---|---|---|
density | boolean | true | Show the density entry. |
setting | boolean | true | Show the column settings entry. |
fixed | boolean | true | Pin buttons in the panel. |
draggable | boolean | true | Drag reordering in the panel. |
Events
The panel does not trigger the table's change event.
| 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; the initial column visibility is restored through update:columns. |
Slots
| Slot | Payload type | Description |
|---|---|---|
columnLabel | { column: ColumnType<TRecord> | ColumnGroupType<TRecord> } | Custom column labels in the panel; columns with a function title show key / dataIndex by default. |
Saving user preferences
When columns are only adjusted on the current page, holding them in a ref is enough. When preferences must survive a reload, be saved to the server per user, or when column definitions change with the locale or permissions, use useColumnState: it combines the source column definitions and the user preferences into a writable columns that you bind to both the table and the panel. After the source definitions update, the recorded preferences are layered onto the new definitions.
const { columns, state, setState, reset, restore, save } = useColumnState(baseColumns, {
storageKey: 'members:columns',
storageType: 'localStorage',
version: 1,
})baseColumnsaccepts an array, a ref or a getter. Assigning tocolumnsonly records preferences and does not write back to the source definitions; renderers, sorters and the like always come from the source definitions.stateis the read-only applied preferences, indexed by paths generated from each column'skey/dataIndex; it can be saved as is and restored throughsetState. Do not rely on how the path strings are concatenated.setStatereplaces the preferences and ignores invalid fields; added columns use the source definitions, and removed columns are not restored.defaultValueis the default preferences given by the application, andresetrestores to it, so do not use it to load preferences the user has saved.resetrestores the first recorded visibility, fixing, order anddefaultValue; it does not restore column width, density, sorting or filtering.- The lock rules also constrain restored preferences, so old storage cannot hide or move protected columns.
Storage, versions and restoring
- With
storageKeyconfigured, preference changes write to storage automatically. Creation inside componentsetuprestores after mount; creation outside a component attempts restoration immediately. Server environments have no browser storage to read unless a customstorageis supplied.storageTypecan belocalStorage/sessionStorage, or you can pass astoragethat implements synchronousgetItem / setItem / removeItem. WithoutstorageKey, no storage is read or written. versiondefaults to1and is stored with the preferences. On initial load, a version mismatch leaves the table using the source columns anddefaultValue.- Adding or removing columns in the source definitions does not require bumping
version: added columns use the source definitions, and removed columns are ignored. Users with saved preferences, however, see added columns at the end of their fixed region. Bumpversionwhen you want new columns to appear at their defined position, or when you changed the default visibility, fixing or order and want everyone to see the new defaults; bumping discards the saved preferences of all users. restore()runs once during initialization or on mount. A missing item, a read or JSON parsing error, or a version mismatch leaves the current preferences intact. A matching version applies stored column preferences on top ofdefaultValue. For example, with the default version, reading{"version":1,"state":null}replaces current preferences with the defaults. Callrestore()from the window'sstorageevent to pick up changes from another tab.savewrites the current preferences to storage. Preference changes andresetboth save automatically, so you usually do not need to call it; after bumpingversion, old data is only overwritten the next time the user changes a preference, so call it once to overwrite immediately.- Unavailable storage and JSON errors are reported through
onError(error)and do not affect rendering.
Saving to the server
The storage adapter is a synchronous interface and does not suit asynchronous requests. To save to the server, do not configure storageKey; load with setState, save by watching state, and carry the version yourself:
const COLUMN_VERSION = 1
const { columns, state, setState, reset } = useColumnState(baseColumns)
let stop: (() => void) | undefined
onMounted(async () => {
try {
const saved = await api.getColumnPreference('system-user')
if (saved?.version === COLUMN_VERSION) setState(saved.state)
} finally {
// Watch only after loading, so the just-loaded preferences are not written back
stop = watch(
state,
debounce((value) => {
api.saveColumnPreference('system-user', { version: COLUMN_VERSION, state: value })
}, 500),
{ deep: true },
)
}
})
onUnmounted(() => stop?.())Before the preferences load, the table displays the source definitions; if you do not want the switch to be visible, render the table after loading completes. The panel's "Reset" and reset() both change state, so they are saved as well.
Saving in application code
Without useColumnState, save only serializable values such as column keys, visibility and density; do not serialize the whole column configuration, or function renderers and sorters are lost. On read, validate the structure, column keys and density value first, then merge them back into the column definitions; groups, fixing, order and versions are yours to handle.
Example of saving visibility for flat columns
watch([columns, size], ([currentColumns, currentSize]) => {
const visibility = currentColumns.flatMap((column) =>
typeof column !== 'symbol' && column.key !== undefined
? [{ key: column.key, visible: column.visible !== false }]
: [],
)
try {
localStorage.setItem('members-table:v1', JSON.stringify({ size: currentSize, visibility }))
} catch {
// Keep the table usable when storage is unavailable.
}
})Without the panel
The panel is built on two table props: the column-level visible controls whether a column is displayed, and the table-level columnOrder controls the display order. You can also use them directly to implement your own column management; the example below toggles visibility with checkboxes and adjusts the order with the ‹ › buttons:
Column visibility: visible
Set visible: false on a column to remove it from the header and body. It is a controlled prop: to display the column again, change visible back or delete the field.
import type { TableColumnsType } from '@vtable-guild/vtable-guild'
interface UserRow {
key: string
name: string
age: number
status: string
}
const columns: TableColumnsType<UserRow> = [
{ title: 'Name', dataIndex: 'name', key: 'name', width: 180 },
// The user unchecked this column in "Column settings"
{ title: 'Age', dataIndex: 'age', key: 'age', width: 96, visible: false },
{ title: 'Status', dataIndex: 'status', key: 'status', width: 140 },
]- Hiding only affects the display layer. Active sort / filter state on the column is not discarded: when you hide a column that is being sorted, the row order is still affected by it, and the sort still applies once the column is displayed again.
- A column group with
visible: falsehides the whole group; when all children of a group are hidden, the empty group is removed as well. - It can be combined with
responsive: the column is not displayed when either condition fails.
Column order: columnOrder
The type of columnOrder is Key[], where Key = string | number. Do not pass it when using the column settings panel.
<template>
<VTable
row-key="key"
:columns="columns"
:data-source="dataSource"
:column-order="['status', 'name']"
/>
</template>With the configuration above, the columns render in the order status → name → age (if columns contains other columns that are not mentioned):
- Columns that appear in
columnOrdercome first in array order; when the same key appears more than once, its first position is used. - Columns that do not appear (including columns without a key) keep their relative order and come after the matched columns.
- The selection / expand columns do not take part in order matching and stay at the start of the row.
- Only top-level columns are reordered: a column group moves as a whole, and moving a child out of its group is not supported.
Known limitations
- Reordering may break the structure where left-fixed columns form a prefix and right-fixed columns form a suffix. In non-virtual mode sticky fixed columns still work, but the fixed column shadows may misbehave when fixed and non-fixed columns are interleaved; with
virtualColumnhorizontal virtualization enabled, a structure that does not hold produces a dev warning and falls back to rendering all columns. - Width overrides from column resizing are recorded by column key and are kept automatically after reordering.
API
TRecord is the application row type. See API Reference for the full table configuration.
useColumnState parameters and options
useColumnState<TRecord>(source, options?) combines source column definitions and serializable user preferences. The complete parameters, options and return values are listed below.
| Parameter | Type | Description |
|---|---|---|
source | MaybeRefOrGetter<TableColumnsType<TRecord>> | Required source column definitions, as an array, ref or getter. |
options | UseColumnStateOptions | Optional default preferences and storage configuration, described below. |
| Option | Type | Default | Description |
|---|---|---|---|
defaultValue | TableColumnState | {} | Default preferences and reset baseline; load saved user preferences with setState or restore. |
storageKey | string | - | Enable automatic preference storage; no storage is read or written when omitted. |
storageType | 'localStorage' | 'sessionStorage' | 'localStorage' | Browser storage type; a supplied storage adapter takes precedence. |
version | string | number | 1 | Stored version; restore only accepts a strictly equal version. |
storage | Pick<Storage, 'getItem' | 'setItem' | 'removeItem'> | - | Optional synchronous storage adapter; use setState and state for asynchronous server preferences. |
onError | (error: unknown) => void | - | Called for storage access or JSON parsing errors. |
useColumnState return value
| Property or method | Type | Description |
|---|---|---|
columns | WritableComputedRef<TableColumnsType<TRecord>> | Writable column definitions with applied preferences; assigning records only the preferences. |
state | ComputedRef<TableColumnState> | Applied serializable preferences to save or watch; use setState to update them. |
setState | (value: TableColumnState) => void | Replace preferences, ignore invalid fields and continue respecting column locks. |
reset | () => void | Restore the first recorded visibility, pinning, order and defaultValue, then save. |
restore | () => void | Keeps current preferences if the stored item is missing, reading or parsing fails, or the version differs. A matching version overlays the stored column preferences on defaultValue. A missing or null state applies only the defaults. |
save | () => void | Save current state and version under storageKey; preference changes also invoke it automatically. |
TableColumnState / TableColumnStateValue
TableColumnState = Record<string, TableColumnStateValue>, with keys provided by the returned state. Save and restore the complete state to preserve generated column paths; each column preference has the fields below.
| Field | Type | Description |
|---|---|---|
visible | boolean | undefined | Visibility of a column or group. |
fixed | 'left' | 'right' | false | undefined | Pinning region of a top-level column or group; false means unpinned. |
order | number | undefined | Order of a top-level column or group within its pinned region, accepting a nonnegative safe integer. |
Props
| Prop | Type | Default | Description |
|---|---|---|---|
columns | TableColumnsType<TRecord> | [] | Column configuration; supports leaf columns, column groups and column placeholder constants. |
columnOrder | Key[] | - | Column display order; see Column display and order. |
Column fields
| Field | Type | Default | Description |
|---|---|---|---|
key | Key | - | Unique column identity; passing it explicitly is recommended. |
visible | boolean | true | Controls whether the column is shown; see Column display and order. |
responsive | Breakpoint[] | - | Shows the column when the current screen matches any of the breakpoints. |
hideInSetting | boolean | false | Hides the column in the column settings panel. |
disable | boolean | { checkbox?: boolean; fixed?: boolean; order?: boolean } | - | Locks column settings actions. Visibility, fixing and ordering can be restricted separately. |
Theming
The classes of the column settings panel can be overridden through the per-instance ui of VTableColumnSettings or the global theme.columnSettings.slots. To adjust colors or sizes, use the CSS variables below. See Three-layer theme overrides for the override order.
ui slots
| Theme config | Slot | Description |
|---|---|---|
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
Use the tabs below to switch between the default classes of the two presets. For how utilities are overridden in the default prebuilt mode, see Prefix and override rules.
createVTableGuild({
theme: {
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: {
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
The table lists the default values for light mode. Dark mode can be overridden separately through .dark.
| Variable | Purpose | antdv | element-plus |
|---|---|---|---|
--vtg-table-row-drop-indicator-color | Color of the drop indicator line in drag sorting | var(--color-primary) | var(--color-primary) |
--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-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
visible and responsive belong to the column configuration, and columnOrder belongs to the table configuration. The props / column configuration are excerpts of the relevant fields; DisplayColumnFields and ColumnOrderFields are documentation helper interfaces, not package exports. See Type reference for the full declarations.
View type declarations
export declare function useColumnState<T extends object>(
source: MaybeRefOrGetter<ColumnsType<T>>,
options?: UseColumnStateOptions,
): {
columns: WritableComputedRef<ColumnsType<T>, ColumnsType<T>>
state: ComputedRef<TableColumnState>
setState: (value: TableColumnState) => void
reset: () => void
restore: () => void
save: () => void
}
export interface TableColumnStateValue {
visible?: boolean
/** Pinning and ordering belong to top-level columns/groups. */
fixed?: 'left' | 'right' | false
order?: number
}
/** Keys are the stable column paths returned by this helper's state. */
export type TableColumnState = Record<string, TableColumnStateValue>
export interface UseColumnStateOptions {
defaultValue?: TableColumnState
storageKey?: string
storageType?: 'localStorage' | 'sessionStorage'
version?: string | number
/** Optional application storage adapter. Only serializable state is stored. */
storage?: Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>
onError?: (error: unknown) => void
}export type TableColumnSettingsSize = 'large' | 'middle' | 'small'export interface TableColumnSettingsOptions {
density?: boolean
setting?: boolean
fixed?: boolean
draggable?: boolean
}export interface TableColumnSettingsProps<TRecord extends object = Record<string, unknown>> {
columns: TableColumnsType<TRecord>
size?: TableColumnSettingsSize
disabled?: boolean
options?: TableColumnSettingsOptions
locale?: Partial<VTableGuildColumnSettingsLocale>
ui?: SlotProps<ColumnSettingsThemeConfig>
class?: string
getPopupContainer?: (trigger: HTMLElement) => HTMLElement
}export interface TableColumnSettingsSlots<TRecord extends object = Record<string, unknown>> {
columnLabel?: (props: { column: ColumnType<TRecord> | ColumnGroupType<TRecord> }) => VNodeChild
}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 type Key = string | numberexport type Breakpoint = 'xxxl' | 'xxl' | 'xl' | 'lg' | 'md' | 'sm' | 'xs'/** ColumnType 节选;文档辅助接口,不是包导出。 */
export interface DisplayColumnFields {
key?: Key
visible?: boolean
responsive?: Breakpoint[]
}/** TableProps 节选;文档辅助接口,不是包导出。 */
export interface ColumnOrderFields {
columnOrder?: Key[]
}