5

I am trying to setup gridstack.js to work with my vue components as it does in this knockout example: https://github.com/troolee/gridstack.js#use-with-knockoutjs/.

Here is a codepen of what I have: https://codepen.io/nyoung697/pen/BperoZ

  1. Add 3 textboxes to the form by clicking 'textbox' 3 times.
  2. Delete the top textbox by hovering overtop and clicking the trash can.

Deleting them from the top down works fine (so it seems). The newest element is at the top, as gridstack is adding it to the top. So this is the last element in the array.

  1. Now try resizing the textboxes and deleting them in a random order.

Gridstack is getting confused and swapping elements around on the page. I have no idea why it is doing this. Can someone please help me figure this out? I have been going around in circles for weeks trying so many different things.

I added some console logging to show what id is being referenced. When you delete the elements in order of the last one added, the id in the "destroyed" method is the same as all the other methods/hooks being hit. However if you try to delete them in a random order, the id that is being printed in the destroyed method is different.

destroyed:

Vue.component('ntextbox', {
  template: '#textboxtemplate',
  props: ['component'],
  created () {
    console.log('created textbox control');
  },
  methods: {
    removeWidget: function(){
      console.log('child remove: ' + $(this.$el).attr('id'));
      this.$emit('remove');
    }
  },
  destroyed () {
    console.log('textbox control destroyed');
    var grid = $('.grid-stack').data('gridstack');
    console.log(grid);
    console.log($(this.$el).attr('id'));
    grid.removeWidget(this.$el);
    //console.log(grid);
  }
});
Nick Young
  • 885
  • 1
  • 10
  • 21
  • Hi @Nick! Were you able to solve this? I guess the reason might be because you are using `v-for="component in resource.components" `, and grid stack script is just getting confused. I'm facing similar problems, you can have a look [here](http://stackoverflow.com/questions/43035128/prerender-vue-js-2-0-component-similar-to-this-compile-in-vue-1) . I'll really appreciate ant info on how it works for you. Thanks! – Olenka Mar 27 '17 at 08:54
  • Hi @Olenka, I haven't solved this with the jQuery library. After more investigation, I decided not to mix different javascript libraries that manage DOM updates. It's too messy. We ended up switching to React for our project and I am using react-grid-layout to do the job. – Nick Young May 13 '17 at 04:16

0 Answers0