dan3460's avatar

Vue Draggable cannot drop in other table

I'm working on a project where i think Vue Draggable is the best solution for what i want to do which is to drag an item from one table and drop it in another. I have been following Andre Madarang video and i have most of it working. I can move thing around within each table but i cannot grab from one and drop in the other, here is the code:

<template>
    <div class="row">
        <div class="col-6">
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title">Available Documents</h5>
                </div>
                <div class="card-body">
                    <table class="table table-sm" id="availDocs">
                        <thead>
                            <tr>
                                <td>ID</td>
                            </tr>
                        </thead>
                        <draggable class="min-height" v-model="approveDocsNew" :list="approveDocsNew" :options="{group:'document'}" :element="'tbody'">
                            <tr v-for="(approveDoc, index) in approveDocsNew">
                                <td>{{approveDoc.document_id}}</td>
                            </tr>
                        </draggable>
                    </table>
                </div>
                <div class="card-footer text-muted">
                    Footer
                </div>
            </div>
        </div>
        <div class="col-6">
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title">Selected Documents</h5>
                </div>
                <div class="card-body">
                    <table class="table table-sm" id="selDocs">
                        <thead>
                            <tr>
                                <td>ID</td>
                            </tr>
                        </thead>
                        <draggable class="min-height" v-model="forApprovalDocsNew" :list="forApprovalDocs" :option="{group:'document'}" :element="'tbody'">
                            <tr v-for="(forApprovalDoc, index) in forApprovalDocsNew">
                                <td>{{forApprovalDoc.document_id}}</td>
                            </tr>
                        </draggable>
                    </table>
                </div>
                <div class="card-footer text-muted">
                    Footer
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import draggable from 'vuedraggable'

    export default {
        components: {
            draggable
        },

        props: ['approvedDocs','forApprovalDocs'],

        data() {
            return {
                approveDocsNew: this.approvedDocs,
                forApprovalDocsNew: this.forApprovalDocs
            }
            
        },

        method: {

        }
    }
</script>

I probably missed something on the tutorial, any ideas?

0 likes
5 replies
dan3460's avatar

I have been working on this the entire morning and i'm getting there. I started from scratch using one of the samples from the vue.draggable web site. Then added and replace things to make it in to a couple of tables and i can move elements from one table to another. Now my problem is when the table is empty or becomes empty, then it does not accept an element. The documentation calls to give the element a minimum height, as you can see in the code below i have been adding the min-height everywhere but it doesn't work. My first attempt was to put the min-height on the draggable element, that did not work. Thanks for any ideas you may have:

<template>
    <div class="row">

        <table class="table dragArea">
            <thead>
                <tr>
                    <th>ID</th>
                </tr>
            </thead>
            <draggable v-model="approveDocsNew" :options="{group:'people'}" :element="'tbody'">
                <tr v-for="element in approveDocsNew" class="dragArea">
                    <td class="dragArea">{{element.document_id}}</td>
                </tr>
            </draggable>
        </table>
        <table class="table dragArea">
            <thead class="table">
                <tr>
                    <th>ID</th>
                </tr>
            </thead>
            <draggable v-model="forApprovalDocsNew" :options="{group:'people'}" :element="'tbody'">
                <tr v-for="element in forApprovalDocsNew" class="dragArea">
                    <td class="dragArea">{{element.document_id}}</td>
                </tr>
            </draggable>
        </table>
    </div>
</template>

<script>
    import draggable from 'vuedraggable'

    export default {
        components: {
            draggable
        },

        props: ['approvedDocs','forApprovalDocs'],

        data() {
            return {
                approveDocsNew: this.approvedDocs,
                forApprovalDocsNew: this.forApprovalDocs
            }
            
        },

        method: {

        }
    }
</script>

<style>
.dragArea {
  min-height: 10px;
}

</style>

topvillas's avatar

Try adding an empty table row if there's no items in forApprovalDocsNew. That might work.

dan3460's avatar

Thanks for the answer, right i'm starting with both tables with some data. The problem becomes when one of the tables gets empty. It seems to me a lot of programming to keep checking when one of the tables becomes empty, to then add a empty row there. Also i think that row will need to be made non-draggable. I will post on the vue draggable site a issue, and see what the response is. In the mean time i think i will make the tables into lists, which seem to be working

dan3460's avatar

If anyone cares, i found the solution the min-height must be declared at the level for the drop to an empty table to work. Thanks for the help.

jcreech's avatar

@DAN3460 - Could you explain this solution a little more? I am experiencing the same problem. I have put the min-height CSS option on dragArea, but when I look at the element in the browser console, it tells me the dragArea is 0x0 on an empty list. I tried including the dragArea in the class of my draggable component (a table row), but that did not change anything.

Please or to participate in this conversation.