My aim is to add buttons on a table created by datatables.js on its header. My code to add buttons is:
$('#myButton').prependTo($('#myTable_wrapper'));
The problem is i can't find the right timing to add the button. I have tried adding the button right after the table was created but it seems like the wrapper is not yet created at that moment. I also tried adding the button on $(document).ready() but the wrapper is also not yet created at that part of the code.
$(document).ready(function () {
$("#myTable").datatables();
$('#myButton').prependTo($('#myTable_wrapper'));
});
Where is the right part of the code to modify the wrapper?
My aim is to add buttons on a table created by datatables.js on its header. My code to add buttons is:
$('#myButton').prependTo($('#myTable_wrapper'));
The problem is i can't find the right timing to add the button. I have tried adding the button right after the table was created but it seems like the wrapper is not yet created at that moment. I also tried adding the button on $(document).ready() but the wrapper is also not yet created at that part of the code.
$(document).ready(function () {
$("#myTable").datatables();
$('#myButton').prependTo($('#myTable_wrapper'));
});
Where is the right part of the code to modify the wrapper?
Share Improve this question edited Jan 11, 2014 at 8:19 rajeemcariazo asked Jan 11, 2014 at 8:08 rajeemcariazorajeemcariazo 2,5445 gold badges38 silver badges63 bronze badges1 Answer
Reset to default 6You need to use the fnDrawCallback callback:
$(document).ready(function() {
$('#myTable').dataTable({
"fnDrawCallback": function(oSettings) {
$('#myButton').prependTo($('#myTable_wrapper'));
}
});
});
Hope that works for you!
Here's a list of many other callbacks: http://datatables/usage/callbacks
Good luck with this.