Skip to content

Selection alert ​

VTableSelectionAlert shares the controlled selectedRowKeys with the table. It shows the count based on the keys and provides a clear control and a slot for application actions. You can place it above the table, in the toolbar extension row or in a pagination content slot.

Cross-page batch actions ​

The example below simulates remote pagination with two pages of data. Check records on both pages and you will see that the selected count includes records that are not currently loaded, while selectedRows in the slot contains only the loaded records passed in by the application. Batch actions use the keys and do not depend on whether the current page's data is complete.

Edit in Playground

The alert counts controlled selectedRowKeys, so it can show keys retained by application code across pages even without preserve enabled on the table. Set preserveSelectedRowKeys: true on the table if its selection callbacks need to return selected records from earlier pages. The alert slot's selectedRows comes from the alert's prop of the same name; it does not automatically read the table's record cache. Application code can pass the selected rows returned by table callbacks to the alert. If selectedRows is omitted, the slot receives an empty array. See Pagination and cross-page selection.

The alert never requests other pages on its own, and it does not turn "all loaded records selected" into "all results on the server". If your application needs to act on every result of a query, define a separate server-side selection protocol.

Controlled state and clearing ​

vue
<VTableSelectionAlert
  v-model:selected-row-keys="selectedRowKeys"
  :selected-rows="availableSelectedRows"
  :loading="batchLoading"
  @clear="handleClear"
>
  <template #actions="{ selectedRowKeys, disabled }">
    <a-button :disabled="disabled" @click="approve(selectedRowKeys)">Batch approve</a-button>
  </template>
</VTableSelectionAlert>

Clearing emits update:selectedRowKeys([]) and then clear(previousKeys, availableRows). Until the parent accepts the update, the displayed count stays at the value passed in. The component does not keep a second copy of the selection state, and it triggers neither the table's change event nor a refresh request.

disabled or loading disables the default clear control, and disabled in the slot reflects both states. Application buttons bind that value themselves. By default the whole alert is hidden when nothing is selected; alwaysShow displays the zero-selection state, in which the clear button is disabled.

Visibility transitions ​

The alert uses a height expansion or collapse with a fade lasting about 180ms by default. Its height follows the actual content, including wrapped text and buttons; once the leave transition finishes, the alert no longer occupies space. Transitions run only when the alert changes between hidden and visible. Changes to the selected count update the content without replaying the transition.

If the alert needs spacing after toolbar buttons, place that spacing inside the alert's collapsible region so it disappears together with the alert:

vue
<VTableSelectionAlert
  v-model:selected-row-keys="selectedRowKeys"
  style="--vtg-selection-alert-spacing-before: 16px"
/>

Use --vtg-selection-alert-motion-duration to adjust the duration; set it to 0s to disable transitions. The component also respects the system's reduced-motion preference. alwaysShow keeps the alert visible, so clearing the selection does not collapse it.

API ​

TRecord is the application row type.

Props ​

PropTypeDefaultDescription
selectedRowKeysreadonly Key[]RequiredControlled selected keys; the count is computed from them alone. Use with v-model:selected-row-keys.
selectedRowsreadonly TRecord[][]Selected records the application currently holds; may be fewer than the keys.
alwaysShowbooleanfalseKeep the alert visible when nothing is selected.
showClearbooleantrueWhether to show the default clear action.
disabledbooleanfalseDisable built-in actions and pass the disabled state to application slots.
loadingbooleanfalseLoading state of the batch action; also disables clearing.
localeobject-Per-instance text overrides; fields are listed in Themes and locales.
uiobject-Per-instance slot class overrides; available slots are listed in ui slots.
classstring-Class for the root element.

Events ​

EventPayloadDescription
update:selectedRowKeys(keys: Key[]) => voidRequests an update of the selected keys; the payload is [] when clearing.
clear(selectedRowKeys: readonly Key[], selectedRows: readonly TRecord[]) => voidEmitted after clear is clicked; the payload holds the keys and available records from before clearing.

Slots ​

The default clear control governed by showClear sits in the action area on the right, together with actions.

SlotPayload typeDescription
infoTableSelectionAlertSlotProps<TRecord>Replaces the count text on the left.
actionsTableSelectionAlertSlotProps<TRecord>Application actions on the right, next to the default clear action.

Slot Props ​

Both info and actions receive TableSelectionAlertSlotProps<TRecord>.

FieldTypeDescription
selectedRowKeysreadonly Key[]Snapshot of the selected keys.
selectedRowsreadonly TRecord[]Snapshot of the available records.
countnumberNumber of keys.
disabledbooleandisabled || loading.
loadingbooleanCurrent loading state.
clear() => voidThe same controlled update request as the default clear action.

VTable row selection options ​

PropTypeDefaultDescription
rowSelectionRowSelection<TRecord>-Enables the row selection column; for its fields, see Row selection · RowSelection.

Themes and locales ​

Use theme.selectionAlert.slots globally and ui per instance.

The text follows the global locale and supports localeOverrides.selectionAlert and the per-instance locale. {count} in the selected text is replaced with the selected count, label is the name of the region and clear is the text of the clear button.

The classes and CSS variables below control the layout, text and clear control of the alert.

ui slots ​

Theme configSlotDescription
theme.selectionAlertwrapperOuter container for visibility transitions and height collapse.
theme.selectionAlertcontentContent container including the spacing before the alert.
theme.selectionAlertrootVisual container of the selection alert.
theme.selectionAlertinfoContainer for the selected count or custom #info content.
theme.selectionAlerttextDefault selected count text.
theme.selectionAlertclearClear selection button.
theme.selectionAlertoptionContainer for the clear selection and batch action areas.
theme.selectionAlertactionsBatch action content container.

Preset defaults ​

ts
createVTableGuild({
  theme: {
    selectionAlert: {
      slots: {
        wrapper: '',
        content: '',
        root: 'box-border flex flex-wrap items-center justify-between gap-x-4 gap-y-2 rounded-[var(--vtg-selection-alert-radius,6px)] bg-[color:var(--vtg-selection-alert-bg,#fafafa)] px-[var(--vtg-selection-alert-padding-inline,24px)] py-[var(--vtg-selection-alert-padding-block,8px)] text-[length:var(--vtg-table-font-size)] font-[family-name:var(--font-family-base)] leading-[var(--vtg-table-line-height)] text-[color:var(--color-muted)]',
        info: 'flex min-w-0 flex-1 flex-wrap items-center',
        text: 'break-words',
        clear: 'shrink-0 border-0 bg-transparent p-0 text-[length:var(--vtg-table-font-size)] text-[color:var(--color-primary)] cursor-pointer hover:text-[color:var(--color-primary-hover)] disabled:cursor-not-allowed disabled:text-[color:var(--color-text-disabled)]',
        option: 'flex min-w-[48px] items-center gap-2 pl-4',
        actions: 'flex min-w-0 flex-wrap items-center gap-2',
      },
    },
  },
})
ts
createVTableGuild({
  themePreset: 'element-plus',
  theme: {
    selectionAlert: {
      slots: {
        wrapper: '',
        content: '',
        root: 'box-border flex flex-wrap items-center justify-between gap-x-4 gap-y-2 rounded-[var(--vtg-selection-alert-radius,6px)] bg-[color:var(--vtg-selection-alert-bg,#fafafa)] px-[var(--vtg-selection-alert-padding-inline,24px)] py-[var(--vtg-selection-alert-padding-block,8px)] text-[length:var(--vtg-table-font-size)] font-[family-name:var(--font-family-base)] leading-[var(--vtg-table-line-height)] text-[color:var(--color-muted)] rounded-[var(--vtg-selection-alert-radius,4px)]',
        info: 'flex min-w-0 flex-1 flex-wrap items-center',
        text: 'break-words',
        clear: 'shrink-0 border-0 bg-transparent p-0 text-[length:var(--vtg-table-font-size)] text-[color:var(--color-primary)] cursor-pointer hover:text-[color:var(--color-primary-hover)] disabled:cursor-not-allowed disabled:text-[color:var(--color-text-disabled)]',
        option: 'flex min-w-[48px] items-center gap-2 pl-4',
        actions: 'flex min-w-0 flex-wrap items-center gap-2 [&>.el-button+.el-button]:!ml-0',
      },
    },
  },
})

CSS variables ​

VariablePurposeantdvelement-plus
--color-primaryTheme primary color, used for drag handle hover, button highlights, field states and more#1677ff#409eff
--vtg-selection-alert-radiusSelection alert radius6px4px
--vtg-selection-alert-bgSelection alert backgroundrgb(0 0 0 / 2%)#fafafa
--vtg-selection-alert-padding-inlineSelection alert horizontal padding24px24px
--vtg-selection-alert-padding-blockSelection alert vertical padding8px8px
--vtg-selection-alert-motion-durationTransition duration of the alert height and opacity; set to 0s to disable transitionsundeclared, falls back to 180msundeclared, falls back to 180ms
--vtg-selection-alert-motion-easingEasing curve of the alert visibility transitionundeclared, falls back to cubic-bezier(0.645, 0.045, 0.355, 1)undeclared, falls back to cubic-bezier(0.645, 0.045, 0.355, 1)
--vtg-selection-alert-spacing-beforeSpacing before the alert, included in its expanded and collapsed heightundeclared, falls back to 0undeclared, falls back to 0

Type Declarations ​

Selection alert types
ts
import type { VNodeChild } from 'vue'
import type {
  Key,
  SlotProps,
  SelectionAlertThemeConfig,
  VTableGuildSelectionAlertLocale,
} from '@vtable-guild/vtable-guild'

export interface TableSelectionAlertProps<TRecord extends object = Record<string, unknown>> {
  selectedRowKeys: readonly Key[]
  selectedRows?: readonly TRecord[]
  alwaysShow?: boolean
  disabled?: boolean
  loading?: boolean
  showClear?: boolean
  locale?: Partial<VTableGuildSelectionAlertLocale>
  ui?: SlotProps<SelectionAlertThemeConfig>
  class?: string
}

export interface TableSelectionAlertSlotProps<TRecord extends object = Record<string, unknown>> {
  selectedRowKeys: readonly Key[]
  selectedRows: readonly TRecord[]
  count: number
  disabled: boolean
  loading: boolean
  clear: () => void
}

export interface TableSelectionAlertSlots<TRecord extends object = Record<string, unknown>> {
  info?: (props: TableSelectionAlertSlotProps<TRecord>) => VNodeChild
  actions?: (props: TableSelectionAlertSlotProps<TRecord>) => VNodeChild
}
ts
export interface VTableGuildSelectionAlertLocale {
  label: string
  selected: string
  clear: string
}
ts
export type SelectionAlertThemeConfig = typeof selectionAlertTheme
export type SelectionAlertSlots = keyof SelectionAlertThemeConfig['slots']
export type QueryThemeConfig = typeof queryTheme
export type QuerySlots = keyof QueryThemeConfig['slots']