簡體   English   中英

如何在 2.0 中獲取 vuetify 數據表選擇的 itemsPerPage?

[英]How to get vuetify data-table selected itemsPerPage in 2.0?

我正在嘗試在 Vuetify 數據表上獲取每頁選定的項目。 似乎已經進行了一些重大更改。 我遵循了這個示例: 如何在 Vuetify DataTable 組件中設置初始“每頁行數”值?

哪個用途

<v-data-table
        :headers="headers"
        :items="equipment"
        class="elevation-1"
        :rows-per-page-items="[15, 30, 50, 100]"
        :pagination.sync="pagination">

data() {
return {
    pagination: {
      rowsPerPage: 30
    }, ...
  }
}

獲取當前選擇的rowsPerPage 這會打印如下錯誤: [BREAKING] 'pagination' has been removed, use 'options' instead. For more information, see the upgrade guide https://github.com/vuetifyjs/vuetify/releases/tag/v2.0.0#user-content-upgrade-guide [BREAKING] 'pagination' has been removed, use 'options' instead. For more information, see the upgrade guide https://github.com/vuetifyjs/vuetify/releases/tag/v2.0.0#user-content-upgrade-guide

我查看了升級指南,幾乎沒有關於頁腳控制分頁的方式,或者現在如何同步每頁選定的行。 我嘗試使用options並在此處查看表格的代碼:

https://github.com/vuetifyjs/vuetify/blob/master/packages/vuetify/src/components/VDataTable/VDataTable.ts#L151

但是,目前還不清楚如何檢索選定的 itemsPerPage,並且在設置 itemsPerPage 時,這些options似乎不能作為反應性道具。 如果有人知道當前執行與 pagination.sync 等效的方法,我們將不勝感激。

您可以使用vuetify 2.x設置每頁的項目和每頁的行數

這是方法,在數據表組件中使用以下屬性

:items-per-page="5" 

您可以將每頁的項目直接設置為數字或分配給數據反應性屬性並動態更新

每頁也有行,將此屬性添加到數據表

:footer-props="footerProps"

在腳本中

data(){
  return {
    footerProps: {'items-per-page-options': [15, 30, 50, 100]},
  }
}

在這里找到工作的codepen:

https://codepen.io/chansv/pen/gOOGPdR?editors=1010

工作代碼:

<div id="app">
  <v-app id="inspire">
    <v-data-table
      :headers="headers"
      :items="desserts"
      :items-per-page="5"
      class="elevation-1"
      :footer-props="footerProps"
      @update:items-per-page="getItemPerPage"
    ></v-data-table>
  </v-app>
</div>

new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data () {
    return {
      footerProps: {'items-per-page-options': [5, 10,15, 30, 50, 100]},
      headers: [
        {
          text: 'Dessert (100g serving)',
          align: 'left',
          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%',
        },
        {
          name: 'Ice cream sandwich',
          calories: 237,
          fat: 9.0,
          carbs: 37,
          protein: 4.3,
          iron: '1%',
        },
        {
          name: 'Eclair',
          calories: 262,
          fat: 16.0,
          carbs: 23,
          protein: 6.0,
          iron: '7%',
        },
        {
          name: 'Cupcake',
          calories: 305,
          fat: 3.7,
          carbs: 67,
          protein: 4.3,
          iron: '8%',
        },
        {
          name: 'Gingerbread',
          calories: 356,
          fat: 16.0,
          carbs: 49,
          protein: 3.9,
          iron: '16%',
        },
        {
          name: 'Jelly bean',
          calories: 375,
          fat: 0.0,
          carbs: 94,
          protein: 0.0,
          iron: '0%',
        },
        {
          name: 'Lollipop',
          calories: 392,
          fat: 0.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.0,
          carbs: 51,
          protein: 4.9,
          iron: '22%',
        },
        {
          name: 'KitKat',
          calories: 518,
          fat: 26.0,
          carbs: 65,
          protein: 7,
          iron: '6%',
        },
      ],
    }
  },
  methods: {
    getItemPerPage(val) {
      console.log(val);
    },
  }
})

簡單的方法: :footer-props="{ itemsPerPageOptions: [25,50,100,-1]}"請注意,-1 用於將“全部”添加到選項中

對於像我一樣正在尋找默認顯示所有行的新選項的任何人,它現在已經更改(-在 v2.2.11 中工作):

老路

:pagination.sync="{ rowsPerPage: -1 }"

新的方法

:items-per-page="-1"

不確定項目和行是否可以互換使用,但這讓我有一段時間感到困惑。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM