最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Add DOM elements on Datatables wrapper - Stack Overflow

programmeradmin0浏览0评论

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 badges
Add a ment  | 

1 Answer 1

Reset to default 6

You 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.

发布评论

评论列表(0)

  1. 暂无评论