How to use callback in buttons action call

How to use callback in buttons action call

datatable_userdatatable_user Posts: 19Questions: 6Answers: 0

I want to use callback because I prefer to set the default row per page with callback rather than setTimeout. However I dont receive any response after execute $.fn.DataTable.ext.buttons.excelHtml5.action.call(dtButton, e, dt, node, config, cb);

I also upgraded button to version 3. Below is my test code

https://jsfiddle.net/qto7yL5a/3/

Snippet:

{
    extend: 'excelHtml5',
    text: 'Excel',
    exportOptions: {
        columns: ':visible'
    },
    title: '',
    action: function(e, dt, node, config) {
        var self = this; //we need this as param for action.call()
        var currentPageLen = dt.page.len();
        var currentPage = dt.page.info().page;

        function cb() {
            console.log("Callback function executed!"); // why does this line is not triggered?

            dt.page.len(currentPageLen).draw(); //set page length
            dt.page(currentPage).draw('page'); //set current page
        }

        dt.one('draw', function() {
            $.fn.DataTable.ext.buttons.excelHtml5.action.call(self, e, dt, node, config, cb); //trigger export

        });

        //draw all before export
        dt.page.len(dt.page.info().recordsTotal).draw();
    }
}

Thanks in advance.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓
      <script src="https://cdn.datatables.net/buttons/2.3.4/js/buttons.html5.min.js"></script>
      <script src="https://cdn.datatables.net/buttons/2.3.4/js/buttons.print.min.js"></script>
    

    Old versions of the Button types are being loaded in. I'd suggest using the download builder to make sure you get the latest versions of everthing.

    Allan

  • datatable_userdatatable_user Posts: 19Questions: 6Answers: 0

    Callback works after updating the links. Thanks!

  • datatable_userdatatable_user Posts: 19Questions: 6Answers: 0

    https://jsfiddle.net/061n2srf/1/

    Updated example incase someone needs it.

Sign In or Register to comment.