Copy row from one table to other without copying the checkbox

Dead End

Here is link https://jsfiddle.net/Palak_js/c8kq2q5d/4/

I am able to add row to other table but,I dont want checkbox to be copied along also when I set default checkbox to be checked it does not works fine. Is there any way I can remove checkbox from other table and by default set checkbox to checked and row gets deleted when checkbox is unchecked

$("#vergeTable input:checkbox.chkclass").click(function() {
  if ($(this).is(":checked")) {
    $(this).closest("tr").clone().appendTo("#vergeTable2");
  } else {
    var index = $(this).closest("tr").attr("data-index");
    var findRow = $("#vergeTable2 tr[data-index='" + index + "']");
    findRow.remove();
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<table class="pure-table dataTable table-bordered vergeTable rowClick" id="vergeTable" role="grid">
  <thead>
    <tr role="row">
      <th align="left" class="sorting_disabled" rowspan="1" colspan="1">Navn</th>
      <th align="left" class="sorting_disabled" rowspan="1" colspan="1">Mandat</th>
      <th align="left" class="sorting_disabled" rowspan="1" colspan="1">Status</th>
      <th align="left" class="sorting_disabled" rowspan="1" colspan="1">Regnskapsplikt</th>
      <th align="left" class="sorting_disabled" rowspan="1" colspan="1">Dato startet</th>
      <th align="left" class="sorting_disabled" rowspan="1" colspan="1">Dato til</th>
      <th align="left" class="sorting_disabled" rowspan="1" colspan="1">Velg</th>
    </tr>
  </thead>
  <tbody>
    <tr data-index="1">
      <td>Alfred Psa Asker</td>
      <td>Ivareta personens interesser innenfor det personlige og økonomiske området</td>
      <td>
        Tidligere
      </td>
      <td>Ordinær</td>
      <td>10.07.2013</td>
      <td>01.10.2016</td>
      <td>
        <input type="checkbox" class="chkclass" />
      </td>
    </tr>

    <tr data-index="2">
      <td>Testfirst Testlast</td>
      <td>Ivareta personens interesser innenfor det personlige og økonomiske området</td>
      <td>
        Nåværende
      </td>
      <td>Ordinær</td>
      <td>05.12.2016</td>
      <td></td>
      <td>
        <input type="checkbox" class="chkclass" />
      </td>
    </tr>
  </tbody>
</table>

<br>-----
<br>

<table class="pure-table dataTable table-bordered selectedVergeTable rowClick" id="vergeTable2" role="grid">
  <thead>
    <tr role="row">
      <th align="left" class="sorting_disabled" rowspan="1" colspan="1">Navn</th>
      <th align="left" class="sorting_disabled" rowspan="1" colspan="1">Mandat</th>
      <th align="left" class="sorting_disabled" rowspan="1" colspan="1">Status</th>
      <th align="left" class="sorting_disabled" rowspan="1" colspan="1">Regnskapsplikt</th>
      <th align="left" class="sorting_disabled" rowspan="1" colspan="1">Dato startet</th>
      <th align="left" class="sorting_disabled" rowspan="1" colspan="1">Dato til</th>
    </tr>
  </thead>
  <tbody>
  </tbody>
</table>

Satpal

You should bind the change event instead of click and you need to remove it from clone object. change() or trigger('change') can be used to trigger the event handler on page load.

//Bind change event
$("#vergeTable input:checkbox.chkclass").change(function() {
    if (this.checked) {
        //Cache cloned object in a variable
        var clone = $(this).closest("tr").clone();
        //Remove checkbox
        clone.find(':checkbox').remove()
            //Append it
        clone.appendTo("#vergeTable2");
    } else {
        var index = $(this).closest("tr").attr("data-index");
        var findRow = $("#vergeTable2 tr[data-index='" + index + "']");
        findRow.remove();
    }
})
.change(); //<==== Trigger on page load 

$("#vergeTable input:checkbox.chkclass").change(function() {
  if (this.checked) {
    //Cache cloned object in a variable
    var clone = $(this).closest("tr").clone();
    //Remove checkbox
    clone.find(':checkbox').remove()
      //Append it
    clone.appendTo("#vergeTable2");
  } else {
    var index = $(this).closest("tr").attr("data-index");
    var findRow = $("#vergeTable2 tr[data-index='" + index + "']");
    findRow.remove();
  }
}).change();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<table class="pure-table dataTable table-bordered vergeTable rowClick" id="vergeTable" role="grid">
  <thead>
    <tr role="row">
      <th align="left" class="sorting_disabled" rowspan="1" colspan="1">Navn</th>
      <th align="left" class="sorting_disabled" rowspan="1" colspan="1">Mandat</th>
      <th align="left" class="sorting_disabled" rowspan="1" colspan="1">Status</th>
      <th align="left" class="sorting_disabled" rowspan="1" colspan="1">Regnskapsplikt</th>
      <th align="left" class="sorting_disabled" rowspan="1" colspan="1">Dato startet</th>
      <th align="left" class="sorting_disabled" rowspan="1" colspan="1">Dato til</th>
      <th align="left" class="sorting_disabled" rowspan="1" colspan="1">Velg</th>
    </tr>
  </thead>
  <tbody>
    <tr data-index="1">
      <td>Alfred Psa Asker</td>
      <td>Ivareta personens interesser innenfor det personlige og økonomiske området</td>
      <td>
        Tidligere
      </td>
      <td>Ordinær</td>
      <td>10.07.2013</td>
      <td>01.10.2016</td>
      <td>
        <input type="checkbox" class="chkclass" checked />
      </td>
    </tr>

    <tr data-index="2">
      <td>Testfirst Testlast</td>
      <td>Ivareta personens interesser innenfor det personlige og økonomiske området</td>
      <td>
        Nåværende
      </td>
      <td>Ordinær</td>
      <td>05.12.2016</td>
      <td></td>
      <td>
        <input type="checkbox" class="chkclass" />
      </td>
    </tr>
  </tbody>
</table>

<br>-----
<br>

<table class="pure-table dataTable table-bordered selectedVergeTable rowClick" id="vergeTable2" role="grid">
  <thead>
    <tr role="row">
      <th align="left" class="sorting_disabled" rowspan="1" colspan="1">Navn</th>
      <th align="left" class="sorting_disabled" rowspan="1" colspan="1">Mandat</th>
      <th align="left" class="sorting_disabled" rowspan="1" colspan="1">Status</th>
      <th align="left" class="sorting_disabled" rowspan="1" colspan="1">Regnskapsplikt</th>
      <th align="left" class="sorting_disabled" rowspan="1" colspan="1">Dato startet</th>
      <th align="left" class="sorting_disabled" rowspan="1" colspan="1">Dato til</th>
    </tr>
  </thead>
  <tbody>
  </tbody>
</table>

Updated Fiddle

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Copy row from one table to other in the editable text box

From Dev

Copy a row from one table to another

From Dev

Jquery - copy a row from one table to another

From Dev

Copying row from one table to another when trigger is called

From Dev

how to copy some values of a row from a table to an other table?

From Dev

How to separate column data to copy from one table to other table?

From Dev

Unable to copy entire row from one sheet to the other with VBA

From Dev

jQuery - copy field from table row and paste it to other fields

From Dev

Copy Data from multiple table to one table without duplicate

From Dev

Copy Data from multiple table to one table without duplicate

From Dev

Copy table row without values

From Dev

Copy table row without values

From Dev

How to copy all hive table from one Database to other Database

From Dev

Copy data from one table to other in Cassandra using Java

From Dev

VBA Excel Copying row from one sheet to other that has a specific value in it

From Dev

Move Row from One MySQL Table to Other after 30 Minutes

From Dev

How to insert a row from one database to the same table in other databases?

From Dev

Copying excel row from one sheet to another

From Dev

Copying row from 1 table to another in SQL

From Dev

Copying from a table row to spreadsheet with formula

From Dev

How to get 2 columns from one table and 2 rows as columns from other table in one row, in MySQL?

From Dev

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

From Dev

Copying a table from one redshift cluster to another redshift cluster(without using s3)

From Dev

Copying data from one table to another

From Dev

Copying a column from one table to another

From Dev

Checkbox won't copy details from one table to another Javascript PHP Ajax

From Dev

GWT CellTable: Selecting one checkbox selects every checkbox/row in the table

From Dev

copy one row from a table to another and insert value of one column in same query

From Dev

copy one row from a table to another and insert value of one column in same query

Related Related

  1. 1

    Copy row from one table to other in the editable text box

  2. 2

    Copy a row from one table to another

  3. 3

    Jquery - copy a row from one table to another

  4. 4

    Copying row from one table to another when trigger is called

  5. 5

    how to copy some values of a row from a table to an other table?

  6. 6

    How to separate column data to copy from one table to other table?

  7. 7

    Unable to copy entire row from one sheet to the other with VBA

  8. 8

    jQuery - copy field from table row and paste it to other fields

  9. 9

    Copy Data from multiple table to one table without duplicate

  10. 10

    Copy Data from multiple table to one table without duplicate

  11. 11

    Copy table row without values

  12. 12

    Copy table row without values

  13. 13

    How to copy all hive table from one Database to other Database

  14. 14

    Copy data from one table to other in Cassandra using Java

  15. 15

    VBA Excel Copying row from one sheet to other that has a specific value in it

  16. 16

    Move Row from One MySQL Table to Other after 30 Minutes

  17. 17

    How to insert a row from one database to the same table in other databases?

  18. 18

    Copying excel row from one sheet to another

  19. 19

    Copying row from 1 table to another in SQL

  20. 20

    Copying from a table row to spreadsheet with formula

  21. 21

    How to get 2 columns from one table and 2 rows as columns from other table in one row, in MySQL?

  22. 22

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

  23. 23

    Copying a table from one redshift cluster to another redshift cluster(without using s3)

  24. 24

    Copying data from one table to another

  25. 25

    Copying a column from one table to another

  26. 26

    Checkbox won't copy details from one table to another Javascript PHP Ajax

  27. 27

    GWT CellTable: Selecting one checkbox selects every checkbox/row in the table

  28. 28

    copy one row from a table to another and insert value of one column in same query

  29. 29

    copy one row from a table to another and insert value of one column in same query

HotTag

Archive