Reputation: 177
I use the DataTable
version 1.10. I want to add dynamically. I know that need to use the table.push()
method for this. But I don't know how can I use the table.push()
method. Is there anyone help me in this regard.
I do like this:
var body = '<tr>';
body += '<td>' +
'<div class="img-container">' +
'<img src="../../assets/img/room-plan/' + r_plan + '" alt="..." id="imgsrc">' +
'</div>' +
'</td>';
body += '<td id="imgname">' + r_name + '</td>';
body += '<td class="text-right">' +
'<a href="#" class="btn btn-simple btn-warning btn-icon edit" data-toggle="modal" data-target="#myModal"><i class="fa fa-edit"></i></a>' +
'<a href="#" class="btn btn-simple btn-danger btn-icon remove" ><i class="fa fa-times"></i></a>' +
'</td>';
body += '</tr>';
$('#datatables').dataTable().fnDestroy();
$(body).appendTo($("tbody"));
// $('#datatables').dataTable();
var table = $('#datatables').DataTable({
"pagingType": "full_numbers",
"lengthMenu": [
[10, 25, 50, -1],
[10, 25, 50, "All"]
],
responsive: true,
language: {
search: "_INPUT_",
searchPlaceholder: "Search records",
//"zeroRecords": " "
}
});
table.push(body);
What is the problem in here?
Upvotes: 1
Views: 53
Reputation: 806
Example:
var newRow = "<tr><td>row 3, cell 1</td><td>row 3, cell 2</td></tr>";
var table = $('table').DataTable();
table.row.add($(newRow)).draw();
Upvotes: 1