copy tables and change selected values

copy tables and change selected values

MadMax76MadMax76 Posts: 149Questions: 33Answers: 1

Hi,

there are quite a lot of threats how to copy rows from one table to another. I also need this, but:
* when copying change some values (especially for keeping track of what was copied)
* there is the header-table and also the items-table; when copying a line in the header-table, I would also want the items (same ID plus item-ID) to be copied

Is that possible and reasonable to do in datatable, or should I better build a function for that in php?

Thanks Max

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,318Questions: 26Answers: 4,948

    Use row().data() to get the row to copy. Do any data manipulations. Then use row.add() to copy/add that row to the destination table. Is this what you are looking for?

    Kevin

  • MadMax76MadMax76 Posts: 149Questions: 33Answers: 1

    Yes, that solves question 1 - changing some values before inserting.
    But how about question 2? To make my problem clearer, here a more detailed description:

    table "offer header" has ID/date/customerNo/remarks
    table "offer lines" has ID/lineNo/product/value

    table "invoice header" has ID/date/customerNo/remarks
    table "invoice lines" has ID/lineNo/product/value

    I want to copy
    "offer header" to "invoice header", putting "copy from offerID ..." into remarks; this should be possible with the APIs you named.
    "offer lines" to "invoice lines" - here all rows with the same ID as in "header" are to be copied.

    Thanks
    Max

  • kthorngrenkthorngren Posts: 21,318Questions: 26Answers: 4,948

    Sorry, I'm not clear on what the question is exactly. I put together this example to demonstrate:
    http://live.datatables.net/nalesixe/1/edit

    Kevin

  • MadMax76MadMax76 Posts: 149Questions: 33Answers: 1

    I try to explain the question differently.

    there are 4 tables.
    With the code you posted in your eaxmple, we copy a row from table1 to table2. Lets assume the ID of this row is 345

    Additionally I want to copy all rows from table 3 to table 4, where the value of column "ID_header" is 345

    Thanks
    Max

  • kthorngrenkthorngren Posts: 21,318Questions: 26Answers: 4,948
    edited August 2021 Answer ✓

    You can use rows().data() to get multiple rows. You can use the rows() row-selector as a function to get the rows that match "ID_header" is 345. Then use rows.add() to add the rows to the second table. Note the s for all the APIs to operate on multiple rows.

    Kevin

Sign In or Register to comment.