Excel Export doesn't work

Excel Export doesn't work

innotableinnotable Posts: 1Questions: 1Answers: 0

neither Flash nor Html5 excel download works in my project (trying in Chrome or FF && ubuntu/windows)

Problem:
the flash excel button appears but downloads empty file
the html5 excel button doesn't throw error but doesnt appear

Facts:
all other buttons get displayed/working
using actual version of Datatable (even nightly html5)
html5 buttons in examples work

Setup:

elem.DataTable({
"aaData":ray,
"aoColumns": col,
"destroy": true,
"dom": 'Bfrtip',
"sScrollX": param.tableScroll,
"buttons":[
'copyHtml5', 'excelHtml5'
],
"order": [[ order.row, order.dir.toLowerCase() ]],
"columnDefs": [{
"render": function(data, type, row){
if(type == "display"){
return moment(data).format("L");
}
else{
return data;
}
}
,"targets": hasDate
}]
});

Dependencys: (in this order (require.js))
'datatables.net',
"datatables.net-bootstrap",
'datatables.net-buttons',
"datatables.net-jszip",
"datatables.net-pdfmake",
"datatables.net-vhf_Fonts",
'datatables.net-buttons-bootstrap',
'datatables.net-buttons-html5',
"datatables.net-buttons-flash",
'datatables.net-buttons-print

i've no idea what could be the problem
i would appreciate every try

Thanks for reading

http://debug.datatables.net/omaged

Answers

  • allanallan Posts: 61,667Questions: 1Answers: 10,096 Site admin

    Can you link to a test case showing the issue please.

    Allan

  • danielmcqdanielmcq Posts: 2Questions: 0Answers: 0

    I had this problem. I matched the load order exactly as in the example but it still happened. Then I tried loading via script tags instead of Require.js and it worked. But I didn't want to use script tags so I tracked down the issue. It's a problem with the jszip and excel modules. The export to Excel code expects the jszip module to be loaded as a global variable, but when jszip loads under require.js, it doesn't do that.
    So in my modules where I need these buttons, I had to do something like this:

    define(["jquery", "jszip","datatables.net-html"], function ($, jszip) {
        // Needed to make DataTables export to Excel work
        window.JSZip = jszip
    

    Just make sure you have jszip in your required list, then attach it to the window global object before doing any DataTable initialization.

  • allanallan Posts: 61,667Questions: 1Answers: 10,096 Site admin

    Thanks for pointing that out! I'll need to look into how Buttons can handle this a bit better. Is there a prescribed way for doing that in RequireJS do you know, or is it simply a case of having it look for JSZip attached to a certain parameter?

    Allan

  • danielmcqdanielmcq Posts: 2Questions: 0Answers: 0

    Either the JSZip module would have to be modified so that it always declares itself as a global variable when it is included using RequireJS, or the "datatables.net-html" module would have to put jszip in its required modules list and then pass it into the main function. But that also requires that the code which uses "datatables.net-html" would have to define a URL for JSZip and make sure it is exported with the same name that "datatables.net-html" would use in its require list.
    Probably the easiest thing to do for DataTables users which want the Export to Excel functionality is document how this needs to be done if they're going to be using AMD/RequireJS.

  • allanallan Posts: 61,667Questions: 1Answers: 10,096 Site admin

    Makes sense - thanks for your input! I've still to fully write up the RequireJS documentation (I really want to find a way to include the CSS as well as the JS for the libraries with a single statement) but when I do I'll make sure this is included.

    Allan

  • aTomimatsuaTomimatsu Posts: 1Questions: 0Answers: 0

    I faced the same problem. Great solution!

This discussion has been closed.