Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vuetify v-data-table drag and drop

I am using V-data-table along with vuex store. Below are the points how I configured my v-data-table

  1. Disabled sort on each column
  2. bind the v-data-table items with vuex state store data
  3. using sortablejs to drag and drop the rows

Problem: When I drag and drop the rows in the v-data-table the I am updating the vuex store(updating the index value on the objects in array with the table row index value). Vuex is updating properly but the data rendered in the v-data-table is not in the order as they are in the vuex state store

Could someone help me on this

The best way I tried to overcome this problem is to force re-render the v-data-table component, but when I do this I cannot drag and drop anymore

Force rendered using the following the template

<template>
  <component-to-re-render :key="componentKey" />
</template>
// script
export default {
  data() {
    return {
      componentKey: 0,
    };
  },
  methods: {
    forceRerender() {
      this.componentKey += 1;  
    }
  }
}
like image 586
Manideep Kothapalli Avatar asked Oct 27 '22 11:10

Manideep Kothapalli


1 Answers

This might not be the optimal solution, but I had a similar problem except I was just using a regular Array. I managed to fix it by calling the Sortable.create() method in updated() life cycle hook.

My guess is that when you call Sortable.create(table, ...) it refers to that instance of the table element. However, when you try to change the table by modifying the key, it changes that instance. Therefore, you need to call Sortable.create() again whenever the vue component is updated.

like image 147
deepmicrobe Avatar answered Nov 16 '22 06:11

deepmicrobe