Use Duplicate button to send data to another table

Use Duplicate button to send data to another table

Khalid TeliKhalid Teli Posts: 251Questions: 71Answers: 0

I was following one of the example in forum live.datatables.net/yokemanu/9/edit to copy data row from one table and send them to another table.
var data = tabletwo.row($(this).closest('tr')).data(); selects all the row data and sends it to another table having same structure as table1.
and if the column names are not matching it show error(unknown field name)
Is there a way to only choose specific columns that I can send to another table

    $('#promotions').on('click', '.duplicatetwo', function(e) {
                e.preventDefault();
               var data = tabletwo.row($(this).closest('tr')).data();
              delete data.DT_RowId;
              editor_replaced.create().set(data).submit();

      });

Thank you
KT

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923
    Answer ✓

    You can manipulate the data variable any way that is needed. The delete data.DT_RowId; statement is removing the unneeded DT_RowId property.

    Kevin

  • rf1234rf1234 Posts: 2,950Questions: 87Answers: 416
    Answer ✓

    Just delete the properties you don't want to copy - like you already do with DT_RowId.

    Something like this should work.

    var data = tabletwo.row($(this).closest('tr')).data();
    delete data.DT_RowId;
    delete data.fieldOneYouDoNotWant;
    delete data.fieldTwoYouDoNotWant;
    
  • Khalid TeliKhalid Teli Posts: 251Questions: 71Answers: 0

    thank you :)

    You guys are just amazing! Bless you

This discussion has been closed.