How to Add new row to datatable using jquery datatable
By FoxLearn 2/16/2024 9:29:50 AM 352
This post shows you how to add new row to datatable using jquery datatable.net
For example
<table border="1"> <thead> <tr><td>Customer ID</td><td>Customer Name</td> <tr> </thead> <tr> <td>01</td> <td>John</td> </tr> <tr> <td>02</td> <td>Lucy</td> </tr> </table>
You can use fnAddData to add row with an array of the values that you want to add.
var table = $('#tbl').DataTable(); var total = table.data().count(); var column1 = 'col 1'; var column2 = 'col 2'; $('#tbl').dataTable().fnAddData([column1, column2 ]);
If you want to embed html control you can write.
var column1 = '<input type="text" id="AddressList_' + total + '__Name" name="AddressList[' + total + '].Name" value="' + data.Name + '">';
And from version 1.10 you can use row.add() method
var newRow = "<tr><td>col 1</td><td>col 2</td></tr>"; var table = $('#tbl').DataTable(); table.row.add($(newRow )).draw();
- How to hide “Showing 1 of N Entries” with jQuery datatables
- How to Change parameter used in datatables ajax url.Action on Ajax.reload
- How to add class to tr using jQuery datatable
- How to fix 'Requested unknown parameter '6' for row 0, column 6'
- Ho to add class to column dynamically using jQuery datatable
- How to remove no data available in table from datatable in jQuery
- How to Rename “show XX entries” dropdown in DataTables
- How to fix Buttons not showing with jQuery datatable bootstrap
Categories
Popular Posts
11 Things You Didn't Know About Cloudflare
12/19/2024