Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to style grouped rows in Vuetify datatable using slots?

Has anybody implemented grouped rows with v-slot in latest Vuetify versions? Their example looks like this:

<template>
  <v-data-table
    :headers="headers"
    :items="desserts"
    item-key="name"
    group-by="category"
    class="elevation-1"
    show-group-by
  ></v-data-table>
</template>

<script>
  export default {
    data () {
      return {
        headers: [
          {
            text: 'Dessert (100g serving)',
            align: 'left',
            value: 'name',
          },
          { text: 'Category', value: 'category' },
        ],
        desserts: [
          {
            name: 'Frozen Yogurt',
            category: 'Ice cream',
          },
          {
            name: 'Ice cream sandwich',
            category: 'Ice cream',
          },
          {
            name: 'Eclair',
            category: 'Cookie',
          },
          {
            name: 'Cupcake',
            category: 'Pastry',
          },
          {
            name: 'Gingerbread',
            category: 'Cookie',
          },
          {
            name: 'Jelly bean',
            category: 'Candy',
          },
          {
            name: 'Lollipop',
            category: 'Candy',
          },
          {
            name: 'Honeycomb',
            category: 'Toffee',
          },
          {
            name: 'Donut',
            category: 'Pastry',
          },
          {
            name: 'KitKat',
            category: 'Candy',
          },
        ],
      }
    },
  }
</script>

This works but I want to roll out my own style. I tried something like this:

<template v-slot:group="data">
   {{data}}
</template>

I see the object, but the styles are missing. It's missing in the docs as far as I can see.

If anybody already implemented something like this, it would be appreciated.

like image 583
wobsoriano Avatar asked Oct 18 '19 06:10

wobsoriano


1 Answers

Yes you can have your own style in group by by adding classes dynamically from items props or hardcoded

Updated the codepen with Vuetify 2.x: https://codepen.io/chansv/pen/wvvzXRj?editors=1010

<div id="app">
  <v-app id="inspire">
    <v-data-table
      :headers="headers"
      :items="desserts"
      item-key="name"
      group-by="category"
      class="elevation-1"
      show-group-by
    >
      <template v-slot:group="props">
   <span class="font-weight-bold">
                 {{props.group }}
              </span>
        <v-data-table
      :headers="props.headers"
      :items="props.items"
      item-key="name"
      hide-default-footer
    >
          <template v-slot:body="{ items }">
            <tbody>
              <tr v-for="item in items" :key="item.name" class="success">
              <td>{{ item.name }}</td>
            </tr>
            </tbody>
          </template>
        </v-data-table>
</template>
   </v-data-table>
  </v-app>
</div>

new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data () {
    return {
      headers: [
        {
          text: 'Dessert (100g serving)',
          align: 'left',
          value: 'name',
        },
        { text: 'Category', value: 'category' },
      ],
      desserts: [
        {
          name: 'Frozen Yogurt',
          category: 'Ice cream',
        },
        {
          name: 'Ice cream sandwich',
          category: 'Ice cream',
        },
        {
          name: 'Eclair',
          category: 'Cookie',
        },
        {
          name: 'Cupcake',
          category: 'Pastry',
        },
        {
          name: 'Gingerbread',
          category: 'Cookie',
        },
        {
          name: 'Jelly bean',
          category: 'Candy',
        },
        {
          name: 'Lollipop',
          category: 'Candy',
        },
        {
          name: 'Honeycomb',
          category: 'Toffee',
        },
        {
          name: 'Donut',
          category: 'Pastry',
        },
        {
          name: 'KitKat',
          category: 'Candy',
        },
      ],
    }
  },
})
like image 109
chans Avatar answered Oct 17 '22 00:10

chans