Copying Data: Products to Order Form

Copying Data: Products to Order Form

roadjanroadjan Posts: 22Questions: 6Answers: 0
edited June 2021 in General

Hi, I am new to datatables but have some experience with LAMP stack. I have editor installed and talking to my database. I am delveloping a sales order processing web app and it seem editor (datatables) could do a lot of the heavy lifting for me as far as data presentation goes. I am happy with everything so far... the thing I can not grasp is how to take data from one table to another, i.e. select products from table1 (products) and add them to another table (order_form). Ideally I would like a button on each row to add that line (product item in table 1) to the order form (table 2). There are many posts about copy data from one table to another, but none that match my use case. Can anybody help?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin
    Answer ✓

    Hi,

    Do you want to do a complete copy? If so, I would suggest using the Editor API along with a custom button to do what you need.

    For example your button would use table.row({selected: true}).data() to get the data for the selected row (row().data()) and then create() to create a new row on the target table and val() to set the values and finally submit() to submit the form.

    If however, you want to reference the product from the order form (a foreign key reference in SQL terms) then you'd need to create the new row in the order form table with an index link to the product (again this can be done with create() / val()).

    Allan

Sign In or Register to comment.