Dynamically add rows into a table using data from another table-jQuery

Litash

I have two table on my page like the picture shown here.enter image description here

What I want to do is:

  1. select rows in the Source Table
  2. read the data in ID field, Name field from the Source Table, and also the value of radio button.
  3. Form these data as rows of Target Table and append these rows into Target Table.

Now Im using two arrays to store the ID and Name that read from Source Table, but im a bit confused about how to form a row for the Target Table.

$('#btnLinkCase').click(function (event) {
var caseID = $('#caseID').text();
var linkedIDArr = []; //array list for selected id
var linkedNameArr = []; //array list for selected name
$('#linkCaseTable tbody tr td:nth-child(2)').each(function (index, el) { //store each paire of <tr> into array
    linkedIDArr.push(el);
});
$('#linkCaseTable tbody tr td:last-child').each(function (index, el) { //store each paire of <tr> into array
    linkedNameArr.push(el);
});
$.each(linkedCaseIDArr, function (index, val) {
    //whats next?
});
});

Please see all source code here

Any ideas of doing this? Thanks in advance

Edit: If multiple rows are selected they will use the same value from the radio button. eg: two rows are selected and "Type 1" is checked. In target table, their relationship all are "Type 1". I hope I have explained myself..

Hiral

Try:

$('button').click(function (event) {
    $("#sourceTable tr:gt(0)").each(function(){
        var th = $(this);
        console.log("dfg")
        if($(th).find("input[name='link-cbx']").is(":checked")){ //assuming ids are unique remove condition if you do notwant so
            var id = $(th).find("td:eq(1)").text();
            var name = $(th).find("td:eq(7)").text();
            var type = "Type "+$("input[name='linkType']:checked").val();
            if($("#targetTable:contains('"+id+"')").length < 1){            
                $("#targetTable").append("<tr><td>"+id+"</td><td>"+name+"</td><td>"+type+"</td></tr>");
            }
        }
    });
});

Updated fiddle here.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to add data to table dynamically using JQuery

From Dev

jquery add/rows to the table dynamically

From Dev

Javascript / jQuery: How to dynamically add rows to table body (using arrays)

From Dev

Dynamically add columns to temp table based on rows in another temp table

From Java

Using data.table to select rows by distance from another row

From Dev

Missing rows when duplicating data from another table using MySQL

From Dev

Add column to table with data from another table

From Dev

Add data from a data table to another using values of a column

From Dev

Inserting rows in a table from another table using a third table

From Dev

Delete rows from a data table that exists in another data table

From Dev

Delete rows from a data table that exists in another data table

From Dev

dynamically add number of rows to table

From Dev

Add/Delete rows in table dynamically

From Dev

select rows from table based on data from another table

From Dev

select rows from table based on data from another table

From Dev

Copy rows of data from one table to another table in same database using pgadmin

From Dev

How to add and manipulate id inside a dynamically generated table rows jquery

From Dev

How to dynamically count rows in a table from two another tables?

From Dev

Oracle Temporary table columns and data from another table's rows

From Dev

Insert new rows into table but copy data from another row in the table

From Dev

How to dynamically add rows with a dynamically generated table

From Dev

MySQL add data from one table to another

From Dev

Dynamically add rows to table in sqlite (using objective c)

From Dev

Insert (multiple) new rows into a table from another table using a subquery?

From Dev

Bgcolor for alternative rows contains select box in a table dynamically using jquery

From Dev

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

From Dev

Insert Data From One Table to Another Table and Add New Values

From Dev

Selecting data from table using another table's data

From Dev

Add/Delete row dynamically to/from jquery table using angularjs not working properly

Related Related

  1. 1

    How to add data to table dynamically using JQuery

  2. 2

    jquery add/rows to the table dynamically

  3. 3

    Javascript / jQuery: How to dynamically add rows to table body (using arrays)

  4. 4

    Dynamically add columns to temp table based on rows in another temp table

  5. 5

    Using data.table to select rows by distance from another row

  6. 6

    Missing rows when duplicating data from another table using MySQL

  7. 7

    Add column to table with data from another table

  8. 8

    Add data from a data table to another using values of a column

  9. 9

    Inserting rows in a table from another table using a third table

  10. 10

    Delete rows from a data table that exists in another data table

  11. 11

    Delete rows from a data table that exists in another data table

  12. 12

    dynamically add number of rows to table

  13. 13

    Add/Delete rows in table dynamically

  14. 14

    select rows from table based on data from another table

  15. 15

    select rows from table based on data from another table

  16. 16

    Copy rows of data from one table to another table in same database using pgadmin

  17. 17

    How to add and manipulate id inside a dynamically generated table rows jquery

  18. 18

    How to dynamically count rows in a table from two another tables?

  19. 19

    Oracle Temporary table columns and data from another table's rows

  20. 20

    Insert new rows into table but copy data from another row in the table

  21. 21

    How to dynamically add rows with a dynamically generated table

  22. 22

    MySQL add data from one table to another

  23. 23

    Dynamically add rows to table in sqlite (using objective c)

  24. 24

    Insert (multiple) new rows into a table from another table using a subquery?

  25. 25

    Bgcolor for alternative rows contains select box in a table dynamically using jquery

  26. 26

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

  27. 27

    Insert Data From One Table to Another Table and Add New Values

  28. 28

    Selecting data from table using another table's data

  29. 29

    Add/Delete row dynamically to/from jquery table using angularjs not working properly

HotTag

Archive