BlogPlaygroundOne

Data tables

The v-data-table component is used for displaying tabular data. Features include sorting, searching, pagination, grouping, and row selection.

Usage

The standard data table presumes that the entire data set is available locally. Sorting, pagination, and filtering is supported and done internally by the component itself.

Name
Species
Diet
Habitat
African ElephantLoxodonta africanaHerbivoreSavanna, Forests
LionPanthera leoCarnivoreSavanna, Grassland
GiraffeGiraffa camelopardalisHerbivoreSavanna, Grassland
ZebraEquus quaggaHerbivoreSavanna, Grassland
HippopotamusHippopotamus amphibiusHerbivoreRiverbanks, Lakes
MeerkatSuricata suricattaOmnivoreDesert, Savanna
HyenaCrocuta crocutaCarnivoreSavanna, Grassland
ZebraEquus quaggaHerbivoreSavanna, Grassland
OstrichStruthio camelusOmnivoreSavanna, Grassland
CheetahAcinonyx jubatusCarnivoreSavanna, Grassland
<v-data-table :items="items"></v-data-table>
<script setup> const items = [ { name: 'African Elephant', species: 'Loxodonta africana', diet: 'Herbivore', habitat: 'Savanna, Forests', }, // ... more items ] </script>
ads via vuetify

API

ComponentDescription
v-data-tablePrimary Component
v-data-table-headersFunctional Component used to display Data-table headers
v-data-table-footerFunctional Component used to display Data-table footers
v-data-table-rowFunctional Component used to display a single row of a data-table
v-data-table-rowsFunctional Component used to display all of the rows in a data-table
v-checkbox-btnReusable lightweight v-checkbox
Toggle Inline API

Server side tables

This variant of the data table is meant to be used for very large datasets, where it would be inefficient to load all the data into the client. It supports sorting, filtering, pagination, and selection like a standard data table, but all the logic must be handled externally by your backend or database.

ComponentDescription
v-data-table-serverPrimary Component

Find more information and examples on the Server side tables page.

Car Model
Horsepower
Fuel Type
Origin
Price ($)
Ford Mustang450GasolineUSA55000
Tesla Model S670ElectricUSA79999
BMW M3503GasolineGermany70000
Audi RS6591GasolineGermany109000
Chevrolet Camaro650GasolineUSA62000

Virtual tables

The virtual variant of the data table relies, like the standard variant, on all data being available locally. But unlike the standard variant it uses virtualization to only render a small portion of the rows. This makes it well suited for displaying large data sets. It supports client-side sorting and filtering, but not pagination.

ComponentDescription
v-data-table-virtualPrimary Component

Find more information and examples on the Virtual tables page.

Boat Type
Speed(knots)
Length(m)
Price($)
Year
Speedster #03522$300,0002021
OceanMaster #12535$500,0002020
Voyager #22045$700,0002019
WaveRunner #34019$250,0002022
SeaBreeze #42831$450,0002018
HarborGuard #51850$800,0002017
SlickFin #63324$350,0002021
StormBreaker #72238$600,0002020
WindSail #81555$900,0002019
FastTide #93720$280,0002022
Speedster #103522$300,0002021
OceanMaster #112535$500,0002020
Voyager #122045$700,0002019
WaveRunner #134019$250,0002022
SeaBreeze #142831$450,0002018
HarborGuard #151850$800,0002017
SlickFin #163324$350,0002021
StormBreaker #172238$600,0002020
WindSail #181555$900,0002019
FastTide #193720$280,0002022
Speedster #203522$300,0002021
OceanMaster #212535$500,0002020
Voyager #222045$700,0002019
WaveRunner #234019$250,0002022
SeaBreeze #242831$450,0002018

Guide

The v-data-table component is a simple and powerful table manipulation component. It is perfect for showing large amounts of tabular data.

Items

Table items can be objects with almost any shape or number of properties. The only requirement is some form of unique identifier if row selection is being utilized.

Headers

The headers array is the core of the table. It defines which properties to display, their associated labels, how they should be sorted, and what they should look like.
All properties are optional, but at least one of title, value, or key should be present to display more than just an empty column:

const headers = [
  { title: 'No data, just a label' },
  { key: 'quantity' },
  { value: 'price' },
]

Without any headers defined, the table will use all the keys of the first item as headers.

Headers can also be a tree structure with a children property to create multi-row header labels with rowspan and colspan calculated automatically.
Leaf nodes (objects without children) will be used as columns for each item.
Branch nodes (objects with children) support all the same sorting and filtering options as leaf nodes, but cannot be used as columns.

Pyramid
Location
Construction Date
Dimensions
Height(m)
Base(m)
Volume(m³)
Great Pyramid of GizaEgyptc. 2580–2560 BC146.6230.42583285
Pyramid of KhafreEgyptc. 2570 BC136.4215.31477485
Red PyramidEgyptc. 2590 BC1042201602895
Bent PyramidEgyptc. 2600 BC101.1188.61200690
Pyramid of the SunMexicoc. 200 CE652251237097

Keys and values

The key property is used to identify the column in slots, events, filters, and sort functions. It will default to the value property if value is a string.
value maps the column to a property in the items array. If value is not defined it will default to key, so key and value are interchangeable in most cases. The exception to this is reserved keys like data-table-select and data-table-expand which must be defined as key to work properly.
key and value both support dot notation to access properties of nested objects, and value can also be a function to combine multiple properties or do other custom formatting. If value is not a string then key must be defined.

const items = [
  {
    id: 1,
    name: {
      first: 'John',
      last: 'Doe',
    },
  },
]

const headers = [
  { title: 'First Name', value: 'name.first' },
  { title: 'Last Name', key: 'name.last' },
  {
    title: 'Full Name',
    key: 'fullName',
    value: item => `${item.name.first} ${item.name.last}`,
  },
]

Sorting, filtering, pagination

See Data and display.

Customization

Other options are available for setting width, align, fixed, or pass custom props to the header element with headerProps and row cells with cellProps.

Props

There is no shortage of properties available for customizing various aspects of the Data table components.

Density

Using the density prop you are able to give your data tables an alternate style.

Plant
Light
Height
Pet Friendly
Price ($)
FernLow20cmYes20
Snake PlantLow50cmNo35
MonsteraMedium60cmNo50
PothosLow to medium40cmYes25
ZZ PlantLow to medium90cmYes30
Spider PlantBright, indirect30cmYes15
Air PlantBright, indirect15cmYes10
PeperomiaBright, indirect25cmYes20
Aloe VeraBright, direct30cmYes15
Jade PlantBright, direct40cmYes25

Sort icons

You can customize sorting icons using dedicated props as well as control default opacity and spacing with Sass variables.

Dessert (100g serving)
Calories
Fat (g)
Carbs (g)
Protein (g)
Frozen Yogurt1596244
Ice cream sandwich2379374.3
Eclair26216236
Cupcake3053.7674.3

Selection

The show-select prop will render a checkbox in the default header to toggle all rows, and a checkbox for each row.

For more information and examples, see the selection examples page.

Name
Location
Height
Base
Volume
🍎 AppleWashington0.10.070.0001
🍌 BananaEcuador0.20.050.0002
🍇 GrapesItaly0.020.020.00001
🍉 WatermelonChina0.40.30.03
🍍 PineappleThailand0.30.20.005
🍒 CherriesTurkey0.020.020.00001
🥭 MangoIndia0.150.10.0005
🍓 StrawberryUSA0.030.030.00002
🍑 PeachChina0.090.080.0004
🥝 KiwiNew Zealand0.050.050.0001

Simple checkbox

When wanting to use a checkbox component inside of a slot template in your data tables, use the v-checkbox-btn component rather than the v-checkbox component.

Name
Manufacturer
Year
Sales
Exclusive
PlayStation 5Sony202010M
Xbox Series XMicrosoft20206.5M
Nintendo SwitchNintendo201789M
PlayStation 4Sony2013116M
Xbox OneMicrosoft201350M
Nintendo WiiNintendo2006101M

Group by

The group-by prop makes it possible to group rows by one or more attributes.

Category
Dessert (100g serving)
Dairy
Candy(3)
Cookie(2)
Ice cream(2)
Pastry(2)
Toffee(1)

Slots

Header slot

You can use the dynamic slots header.<key> to customize only certain columns. <key> corresponds to the key property in the items found in the headers prop.

ID
Name
Size
Color
Price
Quantity
1T-ShirtMRed19.9910
2Jeans32Blue49.995
3SweaterLGreen29.997
4JacketXLBlack89.993
5SocksOne SizeWhite9.9920

Headers slot

You can also override all the internal headers by using the headers slot. Remember that you will have to re-implement any internal functionality like sorting.

Dessert
Calories
Fat(g)
Carbs(g)
Protein(g)
Iron(%)
Frozen Yogurt15962441
Ice cream sandwich2379374.31
Eclair262162367
Cupcake3053.7674.38
Gingerbread35616493.916

Item slot

Normally you would use the item.<key> slots to render custom markup in specific columns. If you instead need more control over the entire row, you can use the item slot.

ID
Name
Dept
Role
Salary($)
HireDate
Hours/Wk
Location
Status
Score
E001Alice JohnsonEngineeringSoftware Dev$95,0002020-03-1540New YorkFull-Time
4.50
E002Bob CarterSalesAccount Manager$72,0002019-11-0135ChicagoFull-Time
4.20
E003Clara DiazHRRecruiter$65,0002021-06-1032RemotePart-Time
4.00
E004David LeeEngineeringDevOps Engineer$105,0002018-09-2240San FranciscoFull-Time
4.70
E005Ella SmithMarketingSocial Media Mgr$80,0002020-01-0538Los AngelesFull-Time
4.30

Item key slot

You can use the dynamic slots item.<key> to customize only certain columns. <key> is the name of the key property in header items sent to headers. So to customize the calories column we’re using the item.calories slot.

Vegetable
Calories
Fat(g)
Carbs(g)
Protein(g)
Iron(%)
Spinach
23
0.43.62.915%
Kael
49
0.98.84.316%
Broccoli
34
0.46.62.86%
Brussels Sprouts
43
0.38.93.49%
Avocado
160
15923%
Sweet Potato
86
0.120.11.63%
Corn
96
1.5213.42%
Potato
77
0.117.528%
Butternut Squash
45
0.111.714%
Beetroot
43
0.2101.66%

Group header slot

When using the group-by prop, you can customize the group header with the group-header slot. Example below makes the whole row clickable.

Group
Tool Name
Weight(kg)
Length(cm)
Price($)
Tool Type: hand
Tool Type: measuring
Tool Type: power

Group summary slot

By default grouping with group-by shows only the header slot. When you define group-summary slot, additional summary row will appear below the group rows.

Group
Tool Name
Weight(kg)
Length(cm)
Price($)
hand(5)
measuring(3)
power(2)

Loading slot

The loading slot allows you to customize your table’s display state when fetching data. In this example we utilize the v-skeleton-loader component to display a loading animation.

Name
Year
Engine
Horsepower
Torque
Chevrolet Camaro1967V8
375
415
Ford Mustang1965V8
271
312
Dodge Charger1968V8
425
490
Pontiac GTO1964V8
350
445
Plymouth Barracuda1964V8
330
425
Chevrolet Chevelle SS1970V8
450
500
Oldsmobile 4421971V8
340
440
Dodge Challenger1970V8
425
490
AMC Javelin1968V8
315
425
Mercury Cougar1967V8
335
427

Misc

Select All

The example below shows how to use the @keydown event to quickly select all rows in the data table using the Ctrl+A or Cmd+A keyboard shortcut. To begin using the shortcut, click anywhere inside the table first.

Name
Email
Age
Alice Johnsonalice@example.com42
Bob Smithbob@example.com36
Charlie Davischarlie@example.com24
Diana Princediana@example.com30

Examples

The following are a collection of examples that demonstrate more advanced and real world use of the v-data-table component.

CRUD Actions

v-data-table with CRUD actions using a v-dialog component for editing each row

Popular books
Title
Author
Genre
Year
Pages
Actions
To Kill a Mockingbird
Harper LeeFiction1960281
1984
George OrwellDystopian1949328
The Great Gatsby
F. Scott FitzgeraldFiction1925180
Sapiens
Yuval Noah HarariNon-Fiction2011443
Dune
Frank HerbertSci-Fi1965412

Expandable rows

The show-expand prop will render an expand icon on each row. You can customize this with the item.data-table-expand slot. The position of this slot can be changed by adding a column with key: 'data-table-expand' to the headers array.

You can override the rows expand icon via the item.data-table-expand slot. To call upon the expand functionality, pass the slots provided internalItem to the toggleExpand function and add it to a click handler to perform the expand functionality. You can also check the current state of the rows expansion by passing the internalItem to the isExpanded function.

Just like selection, row items require a unique property on each item for expansion to work. The default is id, but you can use the item-value prop to specify a different item property.

Title
Director
Genre
Year
Runtime(min)
The Shawshank RedemptionFrank DarabontDrama1994142
InceptionChristopher NolanSci-Fi2010148
The GodfatherFrancis Ford CoppolaCrime1972175
Pulp FictionQuentin TarantinoCrime1994154
The Dark KnightChristopher NolanAction2008152

Ready for more?

Continue your learning with related content selected by the Team or move between pages by using the navigation links below.