Skip to content

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 ​

Edit in Playground

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 key that is unique among siblings; when omitted, dataIndex and then the position are used. After columns without a stable identity are reordered, a reset may map to the wrong column.
  • A function title is not called by the panel, which shows key / dataIndex by default; provide a label through #columnLabel="{ column }".
  • hideInSetting: true keeps a column and its children out of the panel and out of select-all and reset, without affecting how the table displays them.
  • disable: true locks visibility, fixing and order; the object form locks checkbox, fixed and order separately. 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_COLUMN do not appear in the panel and keep their positions.
  • Checked means visible !== false; a column with responsive may 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 key to 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? ​

SymptomCauseFix
After switching density, neither the selected item nor the row height changesDensity is controlled and size is not boundUse 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 changeThe columns update emitted by the panel is not receivedUse 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 notcolumnOrder is passed as well and overrides the order of columnsRemove columnOrder and write the initial order in columns
After fixing, nothing is visible while scrollingThe table does not scroll horizontallyMake 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 visibilityUse useColumnState().reset()

Panel API ​

Props, events and slots of VTableColumnSettings. TRecord is the application row type.

Props ​

PropTypeDefaultDescription
columnsTableColumnsType<TRecord>RequiredControlled column config; use with v-model:columns and pass the same columns to the table.
size'large' | 'middle' | 'small'follows table themeDensity shared with the table; use with v-model:size.
disabledbooleanfalseDisable the entries and close any open panel.
optionsTableColumnSettingsOptions-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.
localeobject-Per-instance text overrides; follows the global locale by default.
uiobject-Per-instance slot class overrides; available slots are listed in Theming.
classstring-Class for the root element.

options ​

FieldTypeDefaultDescription
densitybooleantrueShow the density entry.
settingbooleantrueShow the column settings entry.
fixedbooleantruePin buttons in the panel.
draggablebooleantrueDrag reordering in the panel.

Events ​

The panel does not trigger the table's change event.

EventPayloadDescription
update:columns(columns: TableColumnsType<TRecord>) => voidColumn visibility, pinning or order changed.
update:size(size: 'large' | 'middle' | 'small') => voidDensity changed.
reset() => void"Reset" was clicked; the initial column visibility is restored through update:columns.

Slots ​

SlotPayload typeDescription
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.

Edit in Playground
ts
const { columns, state, setState, reset, restore, save } = useColumnState(baseColumns, {
  storageKey: 'members:columns',
  storageType: 'localStorage',
  version: 1,
})
  • baseColumns accepts an array, a ref or a getter. Assigning to columns only records preferences and does not write back to the source definitions; renderers, sorters and the like always come from the source definitions.
  • state is the read-only applied preferences, indexed by paths generated from each column's key / dataIndex; it can be saved as is and restored through setState. Do not rely on how the path strings are concatenated.
  • setState replaces the preferences and ignores invalid fields; added columns use the source definitions, and removed columns are not restored.
  • defaultValue is the default preferences given by the application, and reset restores to it, so do not use it to load preferences the user has saved.
  • reset restores the first recorded visibility, fixing, order and defaultValue; 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 storageKey configured, preference changes write to storage automatically. Creation inside component setup restores after mount; creation outside a component attempts restoration immediately. Server environments have no browser storage to read unless a custom storage is supplied. storageType can be localStorage / sessionStorage, or you can pass a storage that implements synchronous getItem / setItem / removeItem. Without storageKey, no storage is read or written.
  • version defaults to 1 and is stored with the preferences. On initial load, a version mismatch leaves the table using the source columns and defaultValue.
  • 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. Bump version when 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 of defaultValue. For example, with the default version, reading {"version":1,"state":null} replaces current preferences with the defaults. Call restore() from the window's storage event to pick up changes from another tab.
  • save writes the current preferences to storage. Preference changes and reset both save automatically, so you usually do not need to call it; after bumping version, 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:

ts
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
ts
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:

Edit in Playground

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.

ts
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: false hides 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.

vue
<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 columnOrder come 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 virtualColumn horizontal 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.

ParameterTypeDescription
sourceMaybeRefOrGetter<TableColumnsType<TRecord>>Required source column definitions, as an array, ref or getter.
optionsUseColumnStateOptionsOptional default preferences and storage configuration, described below.
OptionTypeDefaultDescription
defaultValueTableColumnState{}Default preferences and reset baseline; load saved user preferences with setState or restore.
storageKeystring-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.
versionstring | number1Stored version; restore only accepts a strictly equal version.
storagePick<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 methodTypeDescription
columnsWritableComputedRef<TableColumnsType<TRecord>>Writable column definitions with applied preferences; assigning records only the preferences.
stateComputedRef<TableColumnState>Applied serializable preferences to save or watch; use setState to update them.
setState(value: TableColumnState) => voidReplace preferences, ignore invalid fields and continue respecting column locks.
reset() => voidRestore the first recorded visibility, pinning, order and defaultValue, then save.
restore() => voidKeeps 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() => voidSave 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.

FieldTypeDescription
visibleboolean | undefinedVisibility of a column or group.
fixed'left' | 'right' | false | undefinedPinning region of a top-level column or group; false means unpinned.
ordernumber | undefinedOrder of a top-level column or group within its pinned region, accepting a nonnegative safe integer.

Props ​

PropTypeDefaultDescription
columnsTableColumnsType<TRecord>[]Column configuration; supports leaf columns, column groups and column placeholder constants.
columnOrderKey[]-Column display order; see Column display and order.

Column fields ​

FieldTypeDefaultDescription
keyKey-Unique column identity; passing it explicitly is recommended.
visiblebooleantrueControls whether the column is shown; see Column display and order.
responsiveBreakpoint[]-Shows the column when the current screen matches any of the breakpoints.
hideInSettingbooleanfalseHides the column in the column settings panel.
disableboolean | { 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 configSlotDescription
theme.columnSettingsrootContainer for the density and column settings triggers.
theme.columnSettingstriggerColumn settings button.
theme.columnSettingsdensityTriggerDensity button.
theme.columnSettingspopupColumn settings overlay.
theme.columnSettingsdensityPopupDensity overlay.
theme.columnSettingsdensityDensity menu option.
theme.columnSettingsheaderColumn settings panel header.
theme.columnSettingsheadingSelect-all heading.
theme.columnSettingsresetReset button.
theme.columnSettingscolumnsColumn list.
theme.columnSettingschildrenNested child column list.
theme.columnSettingsitemColumn list item.
theme.columnSettingsrowColumn option row; serves as the drag carrier.
theme.columnSettingsrowDraggingOutline of the source row being dragged.
theme.columnSettingsrowDropAboveInsertion line above the target row.
theme.columnSettingsrowDropBelowInsertion line below the target row.
theme.columnSettingsrowDropDotDot at the left end of the insertion line.
theme.columnSettingsdragHandleDrag handle.
theme.columnSettingspinActionsPin position button group.
theme.columnSettingspinActionPin position button.
theme.columnSettingspinIconPin position icon.
theme.columnSettingsgroupContainer for a group of columns divided by pin position.
theme.columnSettingsgroupTitlePin position group title.
theme.columnSettingsgroupColumnsColumn list within a group.
theme.columnSettingslabelColumn option label.
theme.columnSettingscheckboxControlCheckbox container.
theme.columnSettingscheckboxCheckbox input element.
theme.columnSettingscheckMarkCheck mark.
theme.columnSettingsindeterminateMarkIndeterminate mark.
theme.columnSettingslabelTextColumn option label text.
theme.columnSettingsemptyMessage 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.

ts
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)]',
      },
    },
  },
})
ts
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.

VariablePurposeantdvelement-plus
--vtg-table-row-drop-indicator-colorColor of the drop indicator line in drag sortingvar(--color-primary)var(--color-primary)
--vtg-table-popup-radiusRadius of table popups such as filtering and batch selection6px2px
--vtg-table-popup-borderTable popup border01px solid var(--vtg-border-color-lighter, var(--color-default))
--vtg-table-popup-padding-blockTable popup vertical padding4px5px
--vtg-table-popup-padding-inlineTable popup horizontal padding4px0px
--vtg-table-popup-shadowTable popup shadow0 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-widthColumn settings panel width224px280px
--vtg-column-settings-radiusRadius of the column settings and density overlaysvar(--vtg-table-popup-radius)var(--vtg-table-popup-radius)
--vtg-column-settings-icon-sizeIcon size of the toolbar and column settings16px16px
--vtg-column-settings-zz-index of the column settings and density overlays10502000
--vtg-column-settings-shadowOverlay shadowvar(--vtg-table-popup-shadow)var(--vtg-table-popup-shadow)
--vtg-column-settings-pin-icon-sizeIcon size of the pin position buttonsundeclared, falls back to 14pxundeclared, 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
ts
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
}
ts
export type TableColumnSettingsSize = 'large' | 'middle' | 'small'
ts
export interface TableColumnSettingsOptions {
  density?: boolean
  setting?: boolean
  fixed?: boolean
  draggable?: boolean
}
ts
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
}
ts
export interface TableColumnSettingsSlots<TRecord extends object = Record<string, unknown>> {
  columnLabel?: (props: { column: ColumnType<TRecord> | ColumnGroupType<TRecord> }) => VNodeChild
}
ts
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
}
ts
export type Key = string | number
ts
export type Breakpoint = 'xxxl' | 'xxl' | 'xl' | 'lg' | 'md' | 'sm' | 'xs'
ts
/** ColumnType 节选;文档辅助接口,不是包导出。 */
export interface DisplayColumnFields {
  key?: Key
  visible?: boolean
  responsive?: Breakpoint[]
}
ts
/** TableProps 节选;文档辅助接口,不是包导出。 */
export interface ColumnOrderFields {
  columnOrder?: Key[]
}