add/delete data-table row

add/delete data-table row

ynasserynasser Posts: 1Questions: 1Answers: 0

in this example https://datatables.net/examples/api/form.html
1) - how I can add a new row
2) - how I can delete a row

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,083Questions: 26Answers: 4,908

    If you are not using the Editor library then you can use row.add() and row().remove() to add and delete rows.

    Kevin

  • colincolin Posts: 15,236Questions: 1Answers: 2,598
    edited September 2018 Answer ✓

    Hi @ynasser,

    You add a row simply with

    var table = $('#example').DataTable();
    table.row.add([1,2,3,4]).draw();
    

    or in the format of the table, something like this:

    table.row.add(['AAA', '<input type="text" id="row-1-age" name="row-1-age" value="1">', '<input type="text" id="row-1-position" name="row-1-position" value="Architect">', '<select size="1" id="row-1-office" name="row-1-office"><option value="AEdinburgh" selected="selected">AEdinburgh</option><option value="ALondon">ALondon</option><option value="New York">New York/option></select>']).draw();
    

    To remove, you can just use row().remove()

    Cheers,

    Colin

This discussion has been closed.