Datatables export button action not working

Datatables export button action not working

alexamatalexamat Posts: 3Questions: 1Answers: 0

Hello,

I'm having similar problems to those who comment on the following stackoverflow question:

http://stackoverflow.com/questions/44018716/datatables-export-button-not-working

The image of the error that appears to me is the same as the one that appears in stackoverflow question:

It looks like the error can be in datatable.buttons.js or in buttons.html5.js.

I have debugged the code and in line 1014 of buttons.html5.js this.processing function is not defined.

I have tried to comment that line and the other calls to this.processing function and everything is going well, it looks like a bug. I'm working with version 1.3.1 of Datatable buttons.

It seems that the actions of the buttons html5 does not have access to the methods of Buttons.

Could anyone check this out?

This is the fiddle that appears in stackoverflow question:

jsFiddle

Thanks and sorry by my english.

This question has an accepted answers - jump to answer

Answers

  • bindridbindrid Posts: 730Questions: 0Answers: 119
    edited May 2017

    try this:

    $(document).ready(function() {
      var exportExtension = '';
        $('#example').DataTable( {
            dom: 'Bfrtip',
            buttons:    [{
                                extend: 'excel',
                        text:       'Excel',
                        customData: function (exceldata) {
                                    exportExtension = 'Excel';
                                    return exceldata;
                              }
                       },{
                        extend: 'csv',
                        text:       'CSV',
                        customData: function (cvsdata) {
                                exportExtension = 'CSV';
                                   return cvsdata;
                                                                                   }
                       }]
        } );
    } );
    
  • alexamatalexamat Posts: 3Questions: 1Answers: 0

    Hello bindrid,

    firs of all, thanks for your reply.

    Your solution does not work for me, because I don't need to change export extension. I've show the fiddle because the error is the same that mine, but in my code I need to update data in datatable using an ajax request, and after, call to the export button action, and in this call is where is the problem.

    Any suggestion?

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    Did you hit run after you pasted it in? I tested it in your fiddle with my console open. I get no errors. From what I see, you are only doing this so you can set the exportExtension value.

  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin
    Answer ✓

    Its a scoping issue. See this thread for my explanation and and example showing it resolved from someone else who asked the same thing.

    Allan

  • alexamatalexamat Posts: 3Questions: 1Answers: 0

    Thank you very much to both, it works for me.

This discussion has been closed.