1

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?

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.