question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dragging multiple rows of a table

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
jrwnzcommented, Jul 5, 2017

@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.

0reactions
David-Desmaisonscommented, Mar 3, 2019

Sortable.js does not allow sorting various element at the same time.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found