JQuery: How to drag multiple rows from one table to another?

slashdottir

Here's the Fiddle

I have a table with draggable rows that are multi-selectable, but I want to drag them en masse to another table and drop them there - not to be appended as additional elements to the other table, but to do some stuff with the information, i.e. form submission.

My example is originally based on another demo I found here: multi drag demo

Here is the HTML code for the basic example of this problem.

<table class="DraggableThings">
  <tr draggable='true'><td >Row 1</td></tr>
  <tr draggable='true'><td >Row 2</td></tr>
  <tr draggable='true'><td >Row 3 </td></tr>
</table>

<table id='menu_table'>
  <tbody>
    <tr>
        <td class='droppableItem' >accomplished</td>
    </tr>
  </tbody>
</table>

Here is the JQuery code

$('.droppableItem')
   .bind('dragenter dragover', false)
   .bind('drop', function(event){
       accomplished($(this),event);
});
$('.DraggableThings tr').bind('click', function () {
   $(this).toggleClass("selected");
});
$('.DraggableThings tr').bind('dragstart', function(event){
  var mytext = event.target.innerText;
  event.originalEvent.dataTransfer.setData('txt', mytext );
});
$('.DraggableThings tr').drag("init", function () {
    return $('.selected');
  }).drag(function (ev, dd) {
    $(this).css({
        top: dd.offsetY,
        left: dd.offsetX
    });
});


function accomplished(thing,event) {
  event.dataTransfer = event.originalEvent.dataTransfer;
  var data = event.dataTransfer.getData('txt');
  log(data + " made it to accomplishments");
}

css

.selected {
  background-color: #ECB;
}

Here's the Fiddle

Hope someone knows the answer Thank you

WindsofTime

Here's a JSFiddle demonstration, but I suggest fixing up the table rows because dragging multiple rows sometimes confuses one table row for another because they're not spaced out that much, so it can't tell to which table row you're trying to place the elements. I made them bigger for testing purposes.

You could do something along the lines of clicking rather than dragging to guarantee you add it to the right category.

It's the same code as in your other question, except we switched it up to action(ui.helper.children(), event); so that we're passing the elements we selected (and their respective text) and the event, which returns the table row's inner text (i.e. accomplished, postponed, and deleted).

The rewritten action code is:

function action(a,b) {
    for(var i = 0; i < a.length; i++)
        log(a[i].innerText + " made it to " + b.target.innerText);
}

We post to the log in a loop, so that we get all the elements we selected separately. b.target.innerText gets the category (again, i.e. accomplished, postponed, and deleted). Not looping through it means we're getting the concatenation of all the elements (e.g. "Row1Row2").

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Insert multiple rows in one table based on number in another table

From Dev

mysql - move rows from one table to another

From Dev

How to update rows that were deleted from one table in the another?

From Dev

Subtract rows of one table from another table

From Dev

How to Drag and Drop from One QListWidget to Another

From Dev

Combine multiple rows in one from same table

From Dev

How do you select multiple rows in one table, but only one row in another?

From Dev

Drag and Drop multiple rows from html table using Jquery

From Dev

MySQL - Select multiple rows from one table whose IDs are stored in another table

From Dev

select multiple column from one table and insert into another as rows

From Dev

Insert multiple rows from select into another table

From Dev

Update multiple rows in one table with differing values from another

From Dev

Field involving multiple rows from another table

From Dev

jQuery Sortable drag elements from one container to another

From Dev

Insert multiple rows with single a query from one table into another in Oracle

From Dev

How to copy rows from one table to another?

From Dev

MYSQL - UPDATE multiple rows from another table

From Dev

How to count rows that got copied from one Hive table to another

From Dev

How to extract multiple rows from a table based on values from multiple columns from another table and then concatenate in SQL?

From Dev

how to copy data from multiple rows of one table to another in sql server?

From Dev

JQuery: How to drag multiple rows from one table to another?

From Dev

Combine multiple rows in one from same table

From Dev

insert multiple rows mysql from another table

From Dev

Update specific rows from one table to another

From Dev

How to insert multiple rows into one table for each id of another table

From Dev

how to select one row from one table and multiple rows from other table using joins in mysql,

From Dev

How to add multiple rows of data from one sql table to another with selection based on checkboxes?

From Dev

How to SELECT none matching rows from one table to another?

From Dev

How to delete rows from one table matching another table?

Related Related

  1. 1

    Insert multiple rows in one table based on number in another table

  2. 2

    mysql - move rows from one table to another

  3. 3

    How to update rows that were deleted from one table in the another?

  4. 4

    Subtract rows of one table from another table

  5. 5

    How to Drag and Drop from One QListWidget to Another

  6. 6

    Combine multiple rows in one from same table

  7. 7

    How do you select multiple rows in one table, but only one row in another?

  8. 8

    Drag and Drop multiple rows from html table using Jquery

  9. 9

    MySQL - Select multiple rows from one table whose IDs are stored in another table

  10. 10

    select multiple column from one table and insert into another as rows

  11. 11

    Insert multiple rows from select into another table

  12. 12

    Update multiple rows in one table with differing values from another

  13. 13

    Field involving multiple rows from another table

  14. 14

    jQuery Sortable drag elements from one container to another

  15. 15

    Insert multiple rows with single a query from one table into another in Oracle

  16. 16

    How to copy rows from one table to another?

  17. 17

    MYSQL - UPDATE multiple rows from another table

  18. 18

    How to count rows that got copied from one Hive table to another

  19. 19

    How to extract multiple rows from a table based on values from multiple columns from another table and then concatenate in SQL?

  20. 20

    how to copy data from multiple rows of one table to another in sql server?

  21. 21

    JQuery: How to drag multiple rows from one table to another?

  22. 22

    Combine multiple rows in one from same table

  23. 23

    insert multiple rows mysql from another table

  24. 24

    Update specific rows from one table to another

  25. 25

    How to insert multiple rows into one table for each id of another table

  26. 26

    how to select one row from one table and multiple rows from other table using joins in mysql,

  27. 27

    How to add multiple rows of data from one sql table to another with selection based on checkboxes?

  28. 28

    How to SELECT none matching rows from one table to another?

  29. 29

    How to delete rows from one table matching another table?

HotTag

Archive