Vuetify数据表格操作行

3

是否可能将每页行数页面导航左对齐,并在同一行中放置一个按钮?

enter image description here


你想要左边还是右边的按钮?图片显示在左边,但根据您的解释,似乎您想要它在右边。 - DjSh
1
是的,我只是想展示一下我所寻找的想法。我想我可以弄清楚对齐方式。 - Zeus
3个回答

2
默认情况下,操作行右对齐。但是有一种方法可以实现您想要的效果:您可以使用自定义分页并隐藏当前选项卡。请参照以下内容进行操作:
 <v-data-table
    :headers="headers"
    :items="desserts"
    :search="search"
    hide-actions
    :pagination.sync="pagination"
  >

在数据表之后添加以下内容:

最初的回答:

<v-layout row justify-center>
    <v-pagination v-model="pagination.page" :length="pages"></v-pagination>
    <v-btn class="test">test</v-btn>
</v-layout>

最初的回答:

在这里查看更多内容

这里有一个Codepen的实例。


我是否仍可以使用 Vuetify 样式的分页元素?还是需要重新创建它们以实现类似的外观? - Zeus
1
您可以使用 prev-iconnext-icon 及其颜色来更改图标。在此处查看更多信息:https://vuetifyjs.com/en/components/paginations。 - DjSh

2
我发现最简单的方法是将按钮添加到您使用的某些数据表格插槽中,并将按钮相对于表格定位。
<v-data-table
    style="position: relative;">

    <template slot="footer">
        <v-btn style="position: absolute; left: 10px; bottom: 10px;">
            test
        </v-btn>
    </template>

</v-data-table> 

1

使用CSS的最简单方法:

在您的数据表中使用模板:

<template v-slot:actions-prepend>
    <v-btn>
        Click me !
    </v-btn>
</template>

CSS:
.my-grid .v-datatable__actions > div:first-child {
   flex: 1;
}

工作代码片段:

new Vue({
  el: '#app',
  methods: {
    onClick() { this.dark = !this.dark; }
  },
  data: {
    dark: true,
    headers: [{
        text: 'Dessert (100g serving)',
        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%'
      }
    ]
  }
})
.my-grid .v-datatable__actions > div:first-child {
    flex: 1;
}
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/vuetify@1.x/dist/vuetify.min.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
<script src="https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify@1.x/dist/vuetify.js"></script>

<div id="app">
  <v-app :dark="dark">
    <v-content>
      <v-data-table :headers="headers" :items="desserts" class="my-grid">
        <template v-slot:items="{item}">
            <tr>
              <td>{{item.name}}</td>
              <td>{{item.calories}}</td>
              <td>{{item.fat}}</td>
              <td>{{item.carbs}}</td>
              <td>{{item.protein}}</td>
              <td>{{item.iron}}</td>
            </tr>
          </template>
        <template v-slot:actions-prepend>
              <v-btn @click="onClick">
                  Switch mode
              </v-btn>
          </template>
      </v-data-table>
    </v-content>
  </v-app>
</div>


你使用的是哪个版本的Vuetify?我在最新的文档中没有看到actions-prepend插槽。 - totalhack
@totalhack 它只适用于旧版本,不确定实际版本是否适用,请在代码片段中查看确切版本。 - Shadam

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接