How can I duplicate a row with inputs and insert it after the duplicate row?

How can I duplicate a row with inputs and insert it after the duplicate row?

gianca7u7gianca7u7 Posts: 6Questions: 2Answers: 0

I have a table that I use as a detail form where I have options like delete and duplicate on each row, but I haven't found a way without other options redrawing the table and losing my duplicates or some being at the end and other rows after the current row.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Is this using Editor? I see you had a trial, but that it's expired. If you are, then you can create a duplicate, as demonstrated in this example.

    Colin

  • gianca7u7gianca7u7 Posts: 6Questions: 2Answers: 0

    I am using datatable

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Editor is an extension for DataTables that adds editing abilities. The example Colin linked to show how a duplicate row can be created in the DataTable with Editor.

    If you aren't using Editor, then you can use the DataTables API to manipulate the table and create your own duplicate controls.

    Allan

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Not sure why your rejected our answers but haven't clarified your question. If you need additional assistance, please clarify your question.

    Allan

  • gianca7u7gianca7u7 Posts: 6Questions: 2Answers: 0

    Sorry for rejecting your answers, but I would like to know if using datatable without an editor it is possible to duplicate a row with entries for a form after the duplicated line and not at the end.

  • kthorngrenkthorngren Posts: 21,337Questions: 26Answers: 4,954
    Answer ✓

    Yes, its possible without the Editor. As Allan explained the insertion location of the duplicated row will depend on how the table is sorted. Here is a very simplistic example:
    https://live.datatables.net/voriracu/1/edit

    It uses row().data() to get the data of the clicked row. Then uses row.add() to insert the row data, duplicating the row. The table is sorted by name so the inserted row will end up next to the clicked row. However if you sort by Age, for example, the inserted row will end up elsewhere based on the sorting of the Age column.

    Possibly you can update the example or provide one that shows your solution so we can provide more specific suggestions.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

Sign In or Register to comment.