Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show all items in Vuetify Data Table instead of 10 rows only?

I'm using a data table from Vuetify:

<v-data-table
  :ref="`sortableTable${index}`"
  class="items-table-container"
  :headers="headers"
  :items="category.items"
  hide-default-footer>

    ...custom rows

</v-data-table>

I noticed that when adding a new item to the table, it wasn't appearing. I verified that the items I'm passing it have 11 items, however the table is only displaying 10 max.

When I looked at the wrapper surrounding the table, I noticed that it had:

overflow-x: auto;
overflow-y: hidden;

however, I'm unable to override it for some reason. I've tried adding the height prop but nothing seems to work.

How can I give the table an auto height, so that it expands no matter how many rows are in the table?

like image 921
J. Jackson Avatar asked Apr 07 '20 04:04

J. Jackson


2 Answers

This issue is happening because you have removed default footer using hide-default-footer, but the pagination is still enabled. Pagination is by default set to show only 10 items per row. You can easily fix this by simply adding disable-pagination options, which disables pagination completely and then you can see all items after 10th index also.

<v-data-table
  :ref="`sortableTable${index}`"
  class="items-table-container"
  :headers="headers"
  :items="category.items"
  hide-default-footer
  disable-pagination>

DEMO:

new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data() {
    return {
      headers: [{text:"Dessert (100g serving)",align:"start",sortable:!1,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: headers=[{name:"Frozen Yogurt",calories:159,fat:6,carbs:24,protein:4,iron:"1%"},{name:"Ice cream sandwich",calories:237,fat:9,carbs:37,protein:4.3,iron:"1%"},{name:"Eclair",calories:262,fat:16,carbs:23,protein:6,iron:"7%"},{name:"Cupcake",calories:305,fat:3.7,carbs:67,protein:4.3,iron:"8%"},{name:"Gingerbread",calories:356,fat:16,carbs:49,protein:3.9,iron:"16%"},{name:"Jelly bean",calories:375,fat:0,carbs:94,protein:0,iron:"0%"},{name:"Lollipop",calories:392,fat:.2,carbs:98,protein:0,iron:"2%"},{name:"Honeycomb",calories:408,fat:3.2,carbs:87,protein:6.5,iron:"45%"},{name:"Donut",calories:452,fat:25,carbs:51,protein:4.9,iron:"22%"},{name:"KitKat",calories:518,fat:26,carbs:65,protein:7,iron:"6%"},{name:"Jelly bean",calories:375,fat:0,carbs:94,protein:0,iron:"0%"},{name:"Lollipop",calories:392,fat:.2,carbs:98,protein:0,iron:"2%"},
{name:"Ice cream sandwich",calories:237,fat:9,carbs:37,protein:4.3,iron:"1%"},{name:"Eclair",calories:262,fat:16,carbs:23,protein:6,iron:"7%"},{name:"Cupcake",calories:305,fat:3.7,carbs:67,protein:4.3,iron:"8%"},
{name:"Ice cream sandwich",calories:237,fat:9,carbs:37,protein:4.3,iron:"1%"},{name:"Eclair",calories:262,fat:16,carbs:23,protein:6,iron:"7%"},{name:"Cupcake",calories:305,fat:3.7,carbs:67,protein:4.3,iron:"8%"}],
    }
  },
})
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/@mdi/[email protected]/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.js"></script>

<div id="app">
  <v-app id="inspire">
    <v-container>
      <v-layout column>
        <v-data-table :headers="headers" 
          :items="desserts" 
          class="elevation-1" 
          hide-default-footer 
          disable-pagination
          dense>
        </v-data-table>
      </v-layout>
    </v-container>
  </v-app>
</div>
like image 167
palaѕн Avatar answered Oct 22 '22 03:10

palaѕн


The default item count per page is 10. use -1 instead of 10. add this line.

:items-per-page="-1"
like image 4
Haley Huynh Avatar answered Oct 22 '22 01:10

Haley Huynh