Guides
Data tables
Search, filter, sort, select, group and act on rows with BaseDataTable.
BaseDataTable wraps Vuetify's v-data-table with the toolbar, filters, column menu, bulk bar, row actions and pagination the template uses everywhere. Every Vuetify prop and slot still works.
BaseDataTable (or BaseMatrixTable for checkbox grids). Do not use v-table or v-data-table directly in pages.The smallest table
<template>
<BaseCard>
<BaseDataTable :headers="headers" :items="customers" />
</BaseCard>
</template>
<script setup lang="ts">
const { t } = useI18n()
const { customers } = useCustomers()
const headers = computed(() => [
{ title: t('customers.headers.name'), key: 'name' },
{ title: t('customers.headers.spent'), key: 'spent', align: 'end' as const },
{ title: t('customers.headers.orders'), key: 'orders', align: 'center' as const },
])
</script>
A complete table
This is the customers table of the demo:
<BaseDataTable
v-model="selected"
v-model:search="search"
v-model:filter-values="filterValues"
item-value="id"
:items="rows"
:headers="headers"
:filters="filters"
:row-actions="rowActions"
:bulk-actions="bulkActions"
:locked-columns="['name']"
:responsive-columns="{ country: 1020 }"
show-select
searchable
show-columns-menu
show-filters
hover
@click:row="(_, { item }) => openQuickView(item.id)"
>
<template #header-actions>
<BaseToggleGroup v-model="view" :items="viewItems" compact fit mandatory />
</template>
<template #item.name="{ item }">
<BaseUserIdentity :name="item.name" :email="item.email" />
</template>
</BaseDataTable>
Props
Prop | Type | Default | Description |
|---|---|---|---|
items | T[] | — | The rows. |
headers | TableHeader[] | — | Vuetify headers: title, key, align, sortable, nowrap… |
item-value | string | id | The unique key of each row. |
searchable | boolean | false | Shows the search field. Bind the text with v-model:search. |
show-filters | boolean | false | Shows the filters menu built from filters. |
filters | TableFilter[] | [] | Filter definitions. Bind the values with v-model:filter-values. |
show-columns-menu | boolean | false | Lets the user hide and show columns. |
locked-columns | string[] | [] | Columns that cannot be hidden. |
excluded-columns | string[] | [] | Columns left out of the columns menu. |
responsive-columns | Record<string, number> | {} | Hides a column while the table is narrower than the given width in pixels. |
show-grouping | boolean | false | Shows the group menu. Limit it with groupable-columns. |
row-actions | TableRowAction<T>[] | [] | Actions in the menu at the end of each row. |
bulk-actions | TableBulkAction[] | [] | Actions in the bar that appears when rows are selected. |
items-per-page-options | number[] | [10, 25, 50, 100] | Page sizes offered in the footer. |
all-rows-option | boolean | false | Adds an “All” page size. |
hide-footer | boolean | false | Hides the pagination footer. |
disable-pagination | boolean | false | Shows every row. |
loading | boolean | false | Shows loading-rows skeleton rows. |
Filters
const filters = computed<TableFilter[]>(() => [
{ key: 'segment', type: 'select', label: t('customers.headers.segment'), options: segmentOptions.value, multiple: true },
{ key: 'status', type: 'radio', label: t('customers.headers.status'), options: statusOptions.value },
{ key: 'marketing', type: 'boolean', label: t('customers.form.marketing') },
{ key: 'spent', type: 'range', label: t('customers.headers.spent'), step: 100, prefix: '$' },
{ key: 'lastOrder', type: 'dateRange', label: t('customers.headers.lastOrder') },
{ key: 'city', type: 'text', label: t('customers.headers.city') },
])
range filters compute their min and max from the data when you leave them out. A select with multiple also matches rows whose value is an array, for example tags.
Row and bulk actions
const rowActions = computed<TableRowAction<Customer>[]>(() => [
{ icon: 'eye', label: t('actions.view'), onClick: (item) => openQuickView(item.id) },
{ icon: 'pencil', label: t('actions.edit'), onClick: openEdit, disabled: () => !can('customers.update') },
{ icon: 'trash-2', label: t('actions.delete'), color: 'error', onClick: confirmDelete },
])
const bulkActions = computed<TableBulkAction[]>(() => [
{ icon: 'trash-2', label: t('actions.delete'), color: 'error', onClick: (ids) => removeMany(ids as string[]) },
])
Slots
Besides every Vuetify slot (item.<key>, group-header, body…), BaseDataTable adds:
Slot | Props | Use |
|---|---|---|
header-actions | — | Controls in the toolbar, such as views as a BaseToggleGroup compact fit. |
row-actions | { item } | Replaces the row actions menu. |
bulk-actions | { selected, clear } | Replaces the bulk bar actions. |
To render the rows as a grid of cards (as products and courses do), use the Vuetify #body slot. Search, filters, sorting and pagination keep working. Give the table a :key that changes with the layout, because slots are read once.
Density
The user's density preference applies to every table through v-defaults-provider in the default layout, so do not set density on a page table.