how to ignore element inside draggable component
so this may be a duplicate but the suggestions I have found have not solved my issue. I am using a draggable component in a table like so
<draggable class="text-left" :element="'tbody'" v-model="workflow.statuses" @start="drag=true" @end="drag=false" @change="updateStatusOrder(workflow.id, workflow.statuses)" ref="table" :options="{animation: 200, handle: '.draggable'}" :sortable="true">
<template v-for="(status, index) in workflow.statuses">
<tr :key="status.order" :class="{'highlight-status': checkValue(status.id)}" @click="showMessage(index, status.workflow_id)" class="draggable">
<th scope="row" class="status-th"><div class="status-order"></div> {{ appendZero(index + 1) }}</th>
<td>{{ status.status }}</td>
<td class="text-center"><i class="fas fa-check text-primary" v-if="status.notify_client"></i></td>
</tr>
</template>
</draggable>
Now with this set up, when I update the order of the table rows it works fine, however I am trying to implement a conditional element inside of the table but when i do this and attempt to change the order of the table row I get an alarm. Here is the table with the conditional element
<draggable class="text-left" :element="'tbody'" v-model="workflow.statuses" @start="drag=true" @end="drag=false" @change="updateStatusOrder(workflow.id, workflow.statuses)" ref="table" :options="{animation: 200, handle: '.draggable'}" :sortable="true">
<template v-for="(status, index) in workflow.statuses">
<tr :key="status.order" :class="{'highlight-status': checkValue(status.id)}" @click="showMessage(index, status.workflow_id)" class="draggable">
<th scope="row" class="status-th"><div class="status-order"></div> {{ appendZero(index + 1) }}</th>
<td>{{ status.status }}</td>
<td class="text-center"><i class="fas fa-check text-primary" v-if="status.notify_client"></i></td>
</tr>
<!-- conditional element -->
<tr v-if="selectedIndex == index && selectedWorkflow === workflow.id" :key="status.id">
<td colspan="3">
<div class="d-flex flex-column align-items-end">
<textarea type="text" class="w-100" cols="5"></textarea>
<div class="d-flex mt-2">
<button class="btn btn-sm btn-primary mr-2">Save</button>
<button class="btn btn-sm btn-secondary" @click="removeRow()">Cancel</button>
</div>
</div>
</td>
</tr>
</template>
</draggable>
Is there a way I can make the draggablecomponent igonre my conditional element when attempting to re order the list? Ive tried handle but no luck.
@boldstar Your template won´t work with vue.draggale. The children itens have to match the list elements unless vue.draggable has no clue on with element/index to update. So inside a v-for with multiple children will not work. You have to try to re-write your template in order to respect the one child by list item.
I was able to get a similar solution using nested tbody's. I'm not sure if this is valid html or not but it will render:
e.g.,
<tbody> <-- dragable element
<tbody>
<tr>
<th> Content </th>
</tr>
<tr>
<td> data </td>
<td> data </td>
<td> data </td>
</tr>
</tbody>
</tbody>
This solves the single child per item problem by wrapping multiple table rows in a nested tbody element which the browser will flatten into a single series of tbody's inside the table.
Here's a working fiddle: https://codepen.io/jwarnes/pen/vMzvJZ