admin管理员组文章数量:1022727
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.
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.
本文标签: javascriptAdd DOM elements on Datatables wrapperStack Overflow
版权声明:本文标题:javascript - Add DOM elements on Datatables wrapper - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745532619a2154818.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论