Dragging multiple rows of a table
See original GitHub issueI have a following problem: I have products which have subproducts. I want to be able to drag the parent products while keeping all children products in order and under the parent. Essentially I have a following structure:
<table>
<thead>...</thead>
<tbody>
<tr>
<td>Parent 1</td>
</tr>
<tr>
<td>Child 1 of parent 1</td>
</tr>
<tr>
<td>Child 2 of parent 1</td>
</tr>
<tr>
<td>Parent 2</td>
</tr>
<tr>
<td>Child 1 of parent 2</td>
</tr>
</tbody>
</table>
I have tried the following:
<draggable v-model="products"
:options="{handle: '.handle', draggable: '.draggable'}"
element="tbody"
>
<template v-for="product in products">
<tr class="draggable">
<td class="handle">
<i class="fa fa-ellipsis-v"></i>
<i class="fa fa-ellipsis-v"></i>
</td>
<td>{{ product.name }}</td>
</tr>
<tr v-for="subproduct in product.subproducts">
<td></td>
<td>{{ subproduct.name }}</td>
</tr>
</template>
</draggable>
and it drags only the parent product(and also adds an undefined
entry to the array).
Without the draggable: '.draggable'
option I cannot drag at all(I can grab the row and move it around, but when I drop it the order doesn’t change).
Is what I’m trying to achieve even possible with the table?
I’d appreciate any assistance.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:9 (3 by maintainers)
Top Results From Across the Web
JQuery: How to drag multiple rows from one table to another?
I have a table with draggable rows that are multi-selectable, but I want to drag them en masse to another table and drop...
Read more >Move or copy cells, rows, and columns - Microsoft Support
Move or copy rows and columns by using the mouse Select the row or column that you want to move or copy. Note:...
Read more >How to easily reorder rows in excel with drag and drop or ...
Select one or more rows. You can select the entire row or just a portion of the row as shown here. Hit Shift+Alt+UpArrow...
Read more >How To Move Multiple Rows and Columns In Excel - YouTube
This excel video tutorial provides a basic introduction on how to move multiple rows and columns the easy way.
Read more >Row Dragging - Angular Data Grid
Row dragging is used to rearrange rows by dragging the row with the mouse. Download v28 of the best Angular Data Grid in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@KKSzymanowski I’ve been working on something similar. The only solution I’ve found is to have a tbody element for each product (containing rows for the product and each subproduct). Then your draggable tag needs element=“table”. This way instead of dragging rows within a tbody, you’re dragging tbodys within a table.
The big problem is including a thead row. It needs to go inside the draggable element (since that’s the table) which means you need a corresponding entry in your product list. That would be fine (if a little hacky), except that you also want to make the thead undraggable, and doing that results in erratic shuffling - often including the thead being pushed down the table - upon the end of any drag. The same thing happens if you make any tbody undraggable. It’s not clear to me why this is.
So if you don’t need a thead row, dragging tbodys within a table works great. If you do need a thead, the best solution I’ve found is putting it in a separate table and just styling it to look like they’re connected.
Sortable.js does not allow sorting various element at the same time.