Vue.Draggable icon indicating copy to clipboard operation
Vue.Draggable copied to clipboard

Drop into multiple dynamic lists

Open marcellopato opened this issue 8 years ago • 5 comments

Hello guys! Thanks for this great job!

I´m trying to drag an item from a list to another like "Trello". The other lists are dynamic, so I´ll never know the number of lists will be rendered. Let me try to explain better:

Scenario:

On the left of the screen, there is this list of items for the manager to distribute for the employers. The other part of the screen are lists of employers (which I´ll never know the right amount) so the manager can drag an item to a single employer and save to the data table on droping.

The problem I am facing is that when I drag to one employer, all the employers receive the same item. And the second issue is that I can´t which event I´ll use to trigger the AJAX request to save to the data base.

Let´s see some code: This image shows what happens when I drag and drop an item to the first guy!

captura de tela 2018-09-25 as 11 01 37

The blade file:

<div class="row" >
          <div class="col-md-12 p20">
          </div>
          <div class="col-md-3  col-sm-3">
            <h5>Leads</h5>
            <ul class="list-group drag p10">
                <draggable class="dragArea"
                           :options="{group:'ITEMS'}"
                           v-model="leads">
                    <li class="list-group-item"
                        v-for="lead, index in leads"
                        :key="lead.no">
                        <span class="badge">No.@{{ lead.id }}</span>
                        <label>
                            @{{ lead.nome }}
                        </label>
                    </li>
                </draggable>
            </ul>
          </div>
          <div class="col-md-3  col-sm-3" v-for="corretor, index in corretores">
          <h5>@{{ corretor.name }}</h5>
              <ul class="list-group drag p10">
                  <draggable class="dragArea"
                             :options="{group:'ITEMS'}"
                             v-model="corretoresComLeads">
                      <li class="list-group-item" v-for="lead, index in corretoresComLeads">
                          <span class="badge">No.@{{ lead.id }}</span>
                        <label>
                            @{{ lead.nome }}
                        </label>
                        <span class="del" v-on:click="deleteItem(lead, index, '2')"><i class="fa fa-times"></i></span>
                      </li>
                  </draggable>
              </ul>
          </div>
        </div>

The script part of the blade file:

@section('scripts')
<script src="//cdn.jsdelivr.net/npm/[email protected]/Sortable.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/Vue.Draggable/2.15.0/vuedraggable.min.js"></script>
   <script>
    var vu = new Vue({
        el: '#app',
        data: {
            leads: {!! $leads !!},
            corretores: {!! $corretores !!},
            corretoresComLeads: [],
            marcado: [],
            leadsCorretor: [],
            corretor: ''
        },
        methods: {
        deleteItem: function(item, index, group){
            switch (group) {
                case '':
                    var ITEMS = this.leads;
                    break;
                case '2':
                    var ITEMS = this.leads2;
                    break;
                case '3':
                    var ITEMS = this.leads3;
                    break;
                case '4':
                    var ITEMS = this.leads4;
                    break;
            }

            ITEMS.splice(index, 1);
        },
	},
    computed: {
        myList: {
            get() {
                return this.leads;
            },
            set(value) {
                this.leads = value;
            }
        },
        myList2: {
            get() {
                return this.items2;
            },
            set(value) {
                this.items2 = value;
            }
        },
        myList3: {
            get() {
                return this.items3;
            },
            set(value) {
                this.items3 = value;
            }
        },
        myList4: {
            get() {
                return this.items4;
            },
            set(value) {
                this.items4 = value;
            }
        },
        enviaLead(id) {
            const vm = this;
            axios.post('/enviaLeads', {
                lead: this.marcado,
                user_id: id,
                status_id: 0
            })
            .then(function (response) {
                document.getElementById(response.data).style.display = "none";
                vm.marcado = []
                vm.corretoresComLeads.push(response)
            }); 
        },
        removeLead(id) {
            const vm = this
            axios.post('/removeLead', {
                id: id,
                user_id: 0
            })
            .then(function (response) {
                vm.corretoresComLeads.splice(response.data.id, 1)
                //vm.corretoresComLeads.$remove(response.data.id)
            });
        }
    }
});
</script>
@endsection
```

marcellopato avatar Sep 25 '18 14:09 marcellopato

Please address this on stackoverflow as per contributing guideline.

David-Desmaisons avatar Sep 28 '18 20:09 David-Desmaisons

How do I do it?

marcellopato avatar Oct 01 '18 14:10 marcellopato

Did someone resolve this?

FerJaraG avatar Jan 18 '19 14:01 FerJaraG

Nobody solved it, even the member @David-Desmaisons . You see this, bro, but i can't image how can you see it and don't help us.

arturcesarmelo avatar Jan 30 '19 22:01 arturcesarmelo

Looks like @David-Desmaisons already answered the question in another thread.

<div v-for="list in lists">
    <draggable v-model="list">
          ......
     </draggable>
<div>

It worked for me.

JimmyTheNerd avatar Jan 22 '20 13:01 JimmyTheNerd