简体   繁体   English

如何合并Vuetify数据表和Vuetify列表?

[英]How to combine a Vuetify data table and Vuetify list?

I need to use this Vuetify data table but with the layout of this Vuetify list . 我需要使用这个Vuetify 数据表 ,但这种布局Vuetify 列表 The list should be searchable and every entry a button. 该列表应该是可搜索的,并且每个条目都是一个按钮。

How to do that? 怎么做?

Here is my result so far: https://codepen.io/anon/pen/ZRqwYG 到目前为止,这是我的结果: https : //codepen.io/anon/pen/ZRqwYG

HTML: HTML:

<div id="app">
  <v-app id="inspire">
    <v-card>

      <v-card-title>
        Vuetify Data-Table + Vuetify List
        <v-spacer></v-spacer>
        <v-text-field
          v-model="search"
          append-icon="search"
          label="Search"
          single-line
          hide-details
        ></v-text-field>
      </v-card-title>

      <v-data-table
        :headers="headers"
        :items="desserts"
        :search="search"
      >

        <template slot="items" slot-scope="props">
              <v-list-tile-content>
                <v-list-tile-title>{{ props.item.name }}</v-list-tile-title>
                <v-list-tile-sub-title class="text--primary">{{ props.item.iron }}</v-list-tile-sub-title>
                <v-list-tile-sub-title>{{ props.item.calories }}</v-list-tile-sub-title>
              </v-list-tile-content>

              <v-list-tile-action>
                <v-list-tile-action-text>{{ props.item.fat }}</v-list-tile-action-text>
                <v-icon color="grey lighten-1">star_border</v-icon>
              </v-list-tile-action>

         </>    
        </template>

        <v-alert slot="no-results" :value="true" color="error" icon="warning">
          Your search for "{{ search }}" found no results.
        </v-alert>

      </v-data-table>

    </v-card>
  </v-app>
</div>

DEMO: https://codepen.io/anon/pen/ZRwLgX?editors=0010 演示: https : //codepen.io/anon/pen/ZRwLgX? editors =0010

You don't need to use Vuetify List to achieve that. 您无需使用Vuetify List即可实现。 You can style the content inside your Vuetify data table rows as per your requirement using Typography classes. 您可以根据需要使用Typography类对Vuetify数据表行中的内容进行样式设置。 I've added onclick listener on the tr tag that toggles the value key of the particular row item which is bound to the star icon. 我在tr标记上添加了onclick侦听器,用于切换绑定到星形图标的特定行项目的值键。

So inside the methods in your JS I've added the toggle function: 因此,在JS方法中,我添加了toggle函数:

 toggle(name) { let index = this.desserts.findIndex(e => e.name == name); if (index > -1) { this.desserts[index].value = !this.desserts[index].value; } } 

And inside your data-table template, each row item is as follows: 在数据表模板中,每个行项目如下:

 <tr style="cursor: pointer" @click="toggle(props.item.name)"> <td> <div class="body-2"> {{props.item.name}} </div> <div class=""> {{props.item.iron}} </div> <div class=""> {{props.item.calories}} </div> </td> <td> <div class="body-2" style="textAlign: center"> {{props.item.fat}}<br/> <v-icon v-if="props.item.value" color="yellow darken-2">star</v-icon> <v-icon v-else color="grey lighten-1">star_border</v-icon> </div> </td> </tr> 

I've used only 2 header items and have commented the rest. 我仅使用了2个标题项,并已注释了其余项。 You can even choose to hide the header completely by using hide-headers props in your data-table 您甚至可以选择通过在数据表中使用hide-headers道具来完全隐藏标题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM