Copying Data: Products to Order Form
Copying Data: Products to Order Form
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
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 thencreate()
to create a new row on the target table andval()
to set the values and finallysubmit()
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