Skip to content

Getting started ​

This page does one thing: get your first vtable-guild table running in an existing Vue 3 + Vite project as quickly as possible.

If you are already using ant-design-vue or element-plus, finish the initialization here first, then continue with the migration and theming pages (currently Chinese-only).

Requirements ​

  • Node ^20.19.0 or >=22.12.0
  • pnpm >=10.28.0
  • Vue ^3.5.0
  • Vite ^5 or newer

Install ​

The component does not require Tailwind CSS in the host project. Install the package:

bash
pnpm add @vtable-guild/vtable-guild@2

Configure the style entry ​

vtable-guild supports three style modes: prebuilt, tailwind3 and tailwind4.

prebuilt ​

If your project does not use Tailwind CSS, import the prebuilt stylesheet entry directly.

For example, in src/main.css:

css
@import '@vtable-guild/vtable-guild/css/style';

This entry ships pre-generated utilities for the library's internal styles. You do not need to install Tailwind CSS, configure @tailwindcss/vite, or scan this library's sources.

tailwind3 ​

If your project uses Tailwind CSS 3, use the Tailwind 3 entry and add the library's preset to your Tailwind config:

js
import vtableGuildTailwind3Preset from '@vtable-guild/vtable-guild/tailwind3-preset'

export default {
  content: [
    './index.html',
    './src/**/*.{vue,ts,tsx,js,jsx}',
    './node_modules/@vtable-guild/**/*.{js,mjs}',
  ],
  presets: [vtableGuildTailwind3Preset],
}
css
@import '@vtable-guild/vtable-guild/css/tailwind3';

@tailwind base;
@tailwind components;
@tailwind utilities;
ts
app.use(createVTableGuild({ cssMode: 'tailwind3' }))

tailwind4 ​

If your project uses Tailwind CSS 4, use the Tailwind 4 entry:

bash
pnpm add -D tailwindcss @tailwindcss/vite
ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import tailwindcss from '@tailwindcss/vite'

export default defineConfig({
  plugins: [vue(), tailwindcss()],
})
css
@import 'tailwindcss';
@import '@vtable-guild/vtable-guild/css/tailwind4';
ts
app.use(createVTableGuild({ cssMode: 'tailwind4' }))

@vtable-guild/vtable-guild/css/style, @vtable-guild/vtable-guild/css/tailwind3 and @vtable-guild/vtable-guild/css/tailwind4 all include:

  • the default antdv preset
  • the element-plus preset
  • theme tokens
  • the base styles required by the components

Switching presets requires no extra CSS.

In prebuilt mode the library's internal utility classes are emitted with the vtg- prefix. In Tailwind 3/4 modes internal classes stay unprefixed. See package consumption (Chinese) for the full rules.

Initialize the plugin ​

Import the global stylesheet and initialize the plugin in your entry file.

For example, in src/main.ts:

ts
import { createApp } from 'vue'
import App from './App.vue'
import { createVTableGuild } from '@vtable-guild/vtable-guild'
import './main.css'

const app = createApp(App)

app.use(createVTableGuild())

app.mount('#app')

The default preset is antdv. To switch to the element-plus look, set themePreset:

ts
app.use(
  createVTableGuild({
    themePreset: 'element-plus',
  }),
)

Minimal example ​

vue
<script setup lang="ts">
import { VTable, type TableColumnsType } from '@vtable-guild/vtable-guild'

interface UserRow {
  key: string
  name: string
  age: number
  status: string
}

const columns: TableColumnsType<UserRow> = [
  { title: 'Name', key: 'name', dataIndex: 'name', width: 180 },
  { title: 'Age', key: 'age', dataIndex: 'age', width: 96, align: 'right', sorter: true },
  {
    title: 'Status',
    key: 'status',
    dataIndex: 'status',
    filters: [
      { text: 'Active', value: 'active' },
      { text: 'Paused', value: 'paused' },
    ],
    onFilter: (value, record) => record.status === value,
  },
]

const dataSource: UserRow[] = [
  { key: '1', name: 'Ada Lovelace', age: 28, status: 'active' },
  { key: '2', name: 'Grace Hopper', age: 32, status: 'paused' },
]
</script>

<template>
  <VTable row-key="key" :columns="columns" :data-source="dataSource" bordered hoverable />
</template>

Where to go next ​

Type Declarations ​

These are the complete plugin and column declarations used on this page. Referenced types and component props are available in the type reference (Chinese).

Type Declarations
ts
export declare function createVTableGuild(options?: VTableGuildOptions): Plugin
ts
export interface VTableGuildOptions {
  themePreset?: ThemePresetName
  cssMode?: VTableGuildCssMode
  classPrefix?: string
  theme?: VTableGuildThemeOverrides
  locale?: LocaleName
  locales?: LocaleRegistry
  localeOverrides?: DeepPartial<VTableGuildLocale>
  /** 安装时读取一次,不支持运行时切换。 */
  compatClass?: boolean
}
ts
export type VTableGuildCssMode = 'prebuilt' | 'tailwind3' | 'tailwind4'
ts
export type ThemePresetName = 'antdv' | 'element-plus'
ts
export type TableColumnsType<TRecord extends object = Record<string, any>> = ColumnsType<TRecord>
ts
export type ColumnsType<TRecord extends object = Record<string, any>> = Array<
  ColumnType<TRecord> | ColumnGroupType<TRecord> | ColumnSentinel
>
ts
export interface ColumnType<TRecord extends object = Record<string, any>> {
  key?: Key
  title?: ColumnTitle<TRecord>
  dataIndex?: DataIndex
  width?: number | string
  align?: AlignType
  ellipsis?: boolean | { showTitle?: boolean }
  className?: string
  colSpan?: number
  customRender?: (ctx: CustomRenderContext<TRecord>) => VNodeChild | RenderedCell
  customCell?: GetComponentProps<TRecord, TRecord>
  customHeaderCell?: GetComponentProps<ColumnType<TRecord> | ColumnGroupType<TRecord>, TRecord>
  fixed?: 'left' | 'right' | true
  resizable?: boolean
  minWidth?: number
  maxWidth?: number
  sorter?: ColumnSorter<TRecord>
  sortOrder?: SortOrder
  defaultSortOrder?: SortOrder
  sortDirections?: SortOrder[]
  filters?: ColumnFilterItem[]
  onFilter?: (value: string | number | boolean, record: TRecord) => boolean
  filterMultiple?: boolean
  filteredValue?: (string | number | boolean)[] | null
  defaultFilteredValue?: (string | number | boolean)[]
  customFilterDropdown?: boolean
  filterSearch?: boolean | ((input: string, filter: ColumnFilterItem) => boolean)
  filterMode?: 'menu' | 'tree'
  filterResetToDefaultFilteredValue?: boolean
  filterDropdownOpen?: boolean
  onFilterDropdownOpenChange?: (visible: boolean) => void
  filtered?: boolean
  filterIcon?: (opt: { filtered: boolean }) => VNodeChild
  filterDropdown?: VNodeChild | ((props: CustomFilterDropdownSlotProps<TRecord>) => VNodeChild)
  showSorterTooltip?: boolean
  visible?: boolean
  responsive?: Breakpoint[]
}
ts
export interface ColumnGroupType<TRecord extends object = Record<string, any>> extends Omit<
  ColumnType<TRecord>,
  | 'dataIndex'
  | 'customRender'
  | 'sorter'
  | 'sortOrder'
  | 'defaultSortOrder'
  | 'sortDirections'
  | 'filters'
  | 'onFilter'
  | 'filterMultiple'
  | 'filteredValue'
  | 'defaultFilteredValue'
  | 'customFilterDropdown'
  | 'filterSearch'
  | 'filterMode'
  | 'filterResetToDefaultFilteredValue'
  | 'filterDropdownOpen'
  | 'onFilterDropdownOpenChange'
  | 'filtered'
  | 'filterIcon'
  | 'filterDropdown'
> {
  children: Array<ColumnType<TRecord> | ColumnGroupType<TRecord>>
}