Vuetify数据表,显示展开的行而不显示列

URL*_*lip 3 vue.js vuetify.js

我正在尝试构建一个包含扩展行的数据表,我希望扩展部分占据父行的整个宽度。不幸的是,展开的行会自动分为几列,因此如果我<div>在 中仅添加一个<template>,它将显示在父行的第一项下方。如何使扩展项目占据表格的整个宽度?

我找到了实现此目的的源代码,但据我了解,语法与我正在使用的 Vuetify 版本不兼容: https: //codepen.io/francobao/pen/mqxMKP

这是我的组件,其中包含<v-data-table>

<template>
  <div class="row">
    <div class="col-12">
      <v-data-table
        :headers="headers"
        hide-default-footer
        item-key="name"
        :items="getServiceProviders"
        show-expand >
        <template v-slot:expanded-item="{ headers, item }" >
            <ServiceProviderDetails :isEditMode="true" :serviceProvider="item" />
        </template>
      </v-data-table>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex';
import ServiceProviderDetails from './ServiceProviderDetails';

export default {
  name: 'ServiceProviderTable',
  components: {
    ServiceProviderDetails
  },
  computed: {
    ...mapGetters(['getServiceProviders'])
  },
  data () {
    return {
      headers: [
        {
          text: 'Name',
          value: 'name'
        },
        {
          text: 'Service Provider ID',
          value: 'serviceProviderId'
        }
      ]
    }
  }
}
</script>
Run Code Online (Sandbox Code Playgroud)

这是要在展开行中显示的组件:

<template>
  <div class="row sp-details">
    <div class="col-4 text-right"><span>Name:</span></div>
    <div class="col-4"><input class="details-input" type="text" v-model="details.name" /></div>
    <div class="col-4"></div>
    <div class="col-4 text-right"><span>PortalUrl:</span></div>
    <div class="col-4"><input class="details-input" type="text" v-model="details.portalUrl" /></div>
    <div class="col-4"></div>
    <div class="col-4 text-right"><span>SupplierId:</span></div>
    <div class="col-4"><input class="details-input" type="text"  v-model="details.supplierId" /></div>
    <div class="col-4"></div>
    <div class="col-4 text-right"><p>Integration Enabled:</p></div>
    <div class="col-4 text-left">
      <span class="integration-switch" v-on:click="toggleIntegration(true)" ><input :checked="details.integrationEnabled" type="radio" />Yes</span>
      <span class="integration-switch" v-on:click="toggleIntegration(false)" ><input :checked="!details.integrationEnabled" type="radio" />No</span>
    </div>
    <div class="col-4"></div>
    <div class="col-8 offset-4 text-left">
      <v-btn class="mr-2" color="secondary" :checked="details.integrationEnabled" v-on:click="$emit('cancel')">Cancel</v-btn>
      <v-btn color="primary" v-on:click="$emit('save', details)">Save</v-btn>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ServiceProviderDetails',
  props: \[ 'isEditMode', 'serviceProvider' \],
  data () {
    return {
      details: {
        name: '',
        portalUrl: '',
        supplierId: '',
        integrationEnabled: false
      }
    }
  },
  mounted() {
    if(this.isEditMode){
      this.details = this.serviceProvider;
    }
  },
  methods: {
    toggleIntegration(isEnabled) {
      this.details.integrationEnabled = isEnabled;
    }
  },
  watch: {
    serviceProvider: function() {
      console.log('in serviceprovider')
      if(this.isEditMode){
        console.log(this.serviceProvider)
        this.details = this.serviceProvider;
      }
    }
  }
}
</script>
Run Code Online (Sandbox Code Playgroud)

表格标题、第一行和展开行如下所示: 在此输入图像描述

Zim*_*Zim 5

扩展项槽接受 2 个参数:{ headers, item }。将标头的长度作为道具传递给组件以确定colspan=包装模板的 td expanded-item...

    <template v-slot:expanded-item="{ headers, item }" >
        <ServiceProviderDetails :isEditMode="true" :serviceProvider="item" :colspan="headers.length" />
    </template>
Run Code Online (Sandbox Code Playgroud)

ServiceProviderDetails 组件...

<template>
  <td :colspan="colspan">
   <div class="row sp-details">
    <div class="col-4 text-right"><span>Name:</span></div>
    <div class="col-4"><input class="details-input" type="text" v-model="details.name" /></div>
    <div class="col-4"></div>
    <div class="col-4 text-right"><span>PortalUrl:</span></div>
    <div class="col-4"><input class="details-input" type="text" v-model="details.portalUrl" /></div>
    <div class="col-4"></div>
    <div class="col-4 text-right"><span>SupplierId:</span></div>
    <div class="col-4"><input class="details-input" type="text"  v-model="details.supplierId" /></div>
    <div class="col-4"></div>
    <div class="col-4 text-right"><p>Integration Enabled:</p></div>
    <div class="col-4 text-left">
      <span class="integration-switch" v-on:click="toggleIntegration(true)" ><input :checked="details.integrationEnabled" type="radio" />Yes</span>
      <span class="integration-switch" v-on:click="toggleIntegration(false)" ><input :checked="!details.integrationEnabled" type="radio" />No</span>
    </div>
    <div class="col-4"></div>
    <div class="col-8 offset-4 text-left">
      <v-btn class="mr-2" color="secondary" :checked="details.integrationEnabled" v-on:click="$emit('cancel')">Cancel</v-btn>
      <v-btn color="primary" v-on:click="$emit('save', details)">Save</v-btn>
    </div>
   </div>
  </td>
</template>


export default {
  name: 'ServiceProviderDetails',
  props: \[ 'isEditMode', 'serviceProvider', 'colspan' \],
  data () {
    return {
      details: {
        name: '',
        portalUrl: '',
        supplierId: '',
        integrationEnabled: false
      }
    }
  },
  mounted() {
    if(this.isEditMode){
      this.details = this.serviceProvider;
    }
  },
  methods: {
    toggleIntegration(isEnabled) {
      this.details.integrationEnabled = isEnabled;
    }
  },
  watch: {
    serviceProvider: function() {
      console.log('in serviceprovider')
      if(this.isEditMode){
        console.log(this.serviceProvider)
        this.details = this.serviceProvider;
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

演示: https: //codeply.com/p/qAbvfBn8ut