New rows can be added to a DataTable using the row.add() API method. Simply call the API function with the data for the new row (be it an array or object).
var t = $("#kt_datatable_example_1").DataTable();
var counter = 1;
$("#kt_datatable_example_1_addrow").on("click", function() {
t.row.add([
counter + ".1",
counter + ".2",
counter + ".3",
counter + ".4",
counter + ".5",
]).draw(false);
counter++;
});
// Automatically add a first row of data
$("#kt_datatable_example_1_addrow").click();
Form Inputs
In order to perform paging, ordering, searching etc, DataTables can remove rows and cells from the document
(i.e. those rows / cells which are not needed are not inserted into the document).
var table = $("#kt_datatable_example_2").DataTable({
columnDefs: [{
orderable: false,
targets: [1, 2, 3]
}]
});
$("#kt_datatable_example_2_submit").click(function() {
var data = table.$("input, select").serialize();
alert(
"The following data would have been submitted to the server: \n\n" +
data.substr(0, 120) + "..."
);
return false;
});