Vuetify v-data-table align center only one column
Asked Answered
P

2

8

i have:

    <v-data-table :headers="headers" :items="tableData" :items-per-page="5" class="elevation-1">

        <template v-slot:item.id="{ item }">
            {{item.id}}
        </template>

How can I align the content of that column vertically center?

Polygynist answered 28/2, 2020 at 14:4 Comment(0)
T
23

You can specify the alignment of each column setting align equal to center in your headers definition. E.g.:

headers: [
  {
    text: 'Dessert (100g serving)',
    align: 'center',
    sortable: false,
    value: 'name',
  },
  { text: 'Calories', value: 'calories' },
  { text: 'Fat (g)', value: 'fat' },
  { text: 'Carbs (g)', value: 'carbs' },
  { text: 'Protein (g)', value: 'protein' },
  { text: 'Iron (%)', value: 'iron' },
],

If that doesn't work in your configuration, try also removing the slot template.

Tiny answered 28/2, 2020 at 14:13 Comment(0)
M
11

Try to wrap that content by a div with class name d-flex justify-center as follows :

<template v-slot:item.id="{ item }">
            <div class="d-flex justify-center">{{item.id}}</div>
        </template>
Megalomania answered 28/2, 2020 at 14:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.