Search code examples
javascriptcssvue.jsvuetify.jsvuetify-datatable

Veutify data table with number of rows that doesn't make the full height of the table


I am trying to use a v-data-table with fixed header and a footer. But I have a problem, if I define a height for the table that's bigger than the height of the rows, the table takes the height that I defined, and the footer stays far away from the rows.

Here is a codepen

Is there a smart way to solve this?

The HTML

<div id="app">
  <v-app id="inspire">
    <div>
    <v-data-table
      height="300"
      v-model="selected"
      :headers="headers"
      fixed-header
      :items="desserts"
      item-key="name"
    >
    </v-data-table>
    </div>
  </v-app>
</div>

JS

new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data () {
    return {
      singleSelect: false,
      selected: [],
      headers: [
        {
          text: 'Dessert (100g serving)',
          align: 'start',
          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' },
      ],
      desserts: [
        {
          name: 'Frozen Yogurt',
          calories: 159,
          fat: 6.0,
          carbs: 24,
          protein: 4.0,
          iron: '1%',
        },
      ],
    }
  },
})

Solution

  • Since the height will just be perceived as CSS, you can try:

    <div id="app">
      <v-app id="inspire">
        <div>
        <v-data-table
          height="auto"
          v-model="selected"
          :headers="headers"
          fixed-header
          :items="desserts"
          item-key="name"
        >
        </v-data-table>
        </div>
      </v-app>
    </div>