Datatables: Export buttons for CSV, Excel, and PDF not working

Datatables: Export buttons for CSV, Excel, and PDF not working

kofboat123kofboat123 Posts: 10Questions: 1Answers: 0

I am using datatables to export a list. The Copy and Print buttons work alright but the CSV, Excel and PDF buttons do not work. When you click on them nothing happens. This the code I have:

<link type="text/css" href="https://cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css" rel="stylesheet">
<link type="text/css" href="https://cdn.datatables.net/buttons/1.1.2/css/buttons.dataTables.min.css" rel="stylesheet">

<script type="text/javascript" src="jquery-1.12.0.min.js"></script>

<script type="text/javascript" src="https://cdn.datatables.net/tabletools/2.2.4/js/dataTables.tableTools.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/tabletools/2.2.2/swf/copy_csv_xls_pdf.swf"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.1.2/js/dataTables.buttons.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.1.2/js/buttons.flash.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
<script type="text/javascript" src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/pdfmake.min.js"></script>
<script type="text/javascript" src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/vfs_fonts.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.1.2/js/buttons.html5.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.1.2/js/buttons.print.min.js"></script>

<script type="text/javascript">
    $(document).ready(function() {
        $('#FlagsExport').DataTable({
            "pageLength": 50,
            dom: 'Bfrtip', 
            buttons: ['copy','csv','excel','pdf','print'] 
        });
    });
</script>

What have I left out?

«1

Answers

  • kofboat123kofboat123 Posts: 10Questions: 1Answers: 0

    Let me add that all the buttons work perfectly well in Google Chrome and Firefox but not IE.

  • AshbjornAshbjorn Posts: 55Questions: 2Answers: 16

    @kofboat123,

    • Are you referring to IE11? Or IE Edge? Or perhaps an older version even?
    • Is this behavior also occurring on the example pages?
    • Does this behavior go away if you do not include the scripts for flash?
    • I also notice you have both the old deprecated TableTools and the Buttons extension loaded, this might prevent either from working correctly?

    I tried https://datatables.net/extensions/buttons/examples/html5/columns.html and it works fine on IE11, IE Edge, FF and Chrome. Perhaps you could do a comparison what might be different with your example?

    Hope this helps,

  • kofboat123kofboat123 Posts: 10Questions: 1Answers: 0

    Thanks Ashbjorn. To answer your questions.
    Yes, I am using IE11 and not IE Edge.
    The behavior was not occurring on the example pages.

    This is what I did:
    I copied the code from the example page and removed all excess code and then inserted my own code in the original and it now works. I used these rather than what I was originally using.

    <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="http://www.datatables.net/rss.xml">
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css">
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.1.2/css/buttons.dataTables.min.css">
    <style type="text/css" class="init"></style>

    <script type="text/javascript" src="jquery-1.12.0.min.js"></script>
    
    <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script>
    <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/1.1.2/js/dataTables.buttons.min.js"></script>
    <script type="text/javascript" language="javascript" src="//cdn.datatables.net/buttons/1.1.2/js/buttons.flash.min.js"></script>
    
  • kofboat123kofboat123 Posts: 10Questions: 1Answers: 0

    It is working now, however, the Excel does not return any value at all when I save. The CSV button returns values.

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin

    We'd really need a link to a page showing the issue so it can be debugged please.

    Thanks,
    Allan

  • kofboat123kofboat123 Posts: 10Questions: 1Answers: 0

    Allan,

    I would not be able to send the link because it is a behind a firewall. However, I get the same problem when I use the export excel button on this page.

    https://datatables.net/extensions/buttons/examples/flash/simple.html

  • kofboat123kofboat123 Posts: 10Questions: 1Answers: 0

    I have now switched to using the flash version hence the example I sent in the earlier post.

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin

    Just to confirm - when using IE11 with this example it doesn't work for you?

    I'm not sure I can explain that since it appears to work okay for me.

    Have you got the latest version of Flash installed and active on the page?

    Allan

  • kofboat123kofboat123 Posts: 10Questions: 1Answers: 0

    Allan,

    Yes, it does not work. This is what I mean by it does not work. All the buttons show, the copy and csv buttons works, the way they are supposed to, the Excel button displays and allows you to save the file. But when you open the Excel file, there is nothing in it.

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin

    But when you open the Excel file, there is nothing in it.

    What are you opening it with? If OpenOffice.org, then that is a known bug in OpenOffice.

    Allan

  • kofboat123kofboat123 Posts: 10Questions: 1Answers: 0

    No, I am opening it with Microsoft Excel 2013 or sometimes Excel 2016.

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin

    I'm afraid I'm a bit of a loss at the moment in that case. I'm not able to reproduce that issue from that page I'm afraid. To be able to help resolve it I would need to be able to do so since I can't debug it at the moment.

    Buttons 1.2 is going to update how the XSLX file is created and its contents, perhaps that will resolve the issue...

    Allan

  • kofboat123kofboat123 Posts: 10Questions: 1Answers: 0

    Thanks Allan. I appreciate your help anyway. I am using csv button in place of the one for Excel and that seems to work perfectly well.
    I want to host the files on our side instead of using cdn folders. Why is it that when I download it to my end, then nothing shows up at all?

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin

    Why is it that when I download it to my end, then nothing shows up at all?

    I'm afraid I've no idea without being able to debug it :-). Perhaps try using the download builder.

    Allan

  • kofboat123kofboat123 Posts: 10Questions: 1Answers: 0

    When I use these, the page works, the way it is supposed to:

    <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script>
    <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/1.1.2/js/dataTables.buttons.min.js"></script>
    <script type="text/javascript" language="javascript" src="//cdn.datatables.net/buttons/1.1.2/js/buttons.flash.min.js"></script>
    

    But when I host them locally, then nothing works...is there something I am supposed to do?

    <script type="text/javascript" language="javascript" src="jquery.dataTables.min.js"></script>
    <script type="text/javascript" language="javascript" src="dataTables.buttons.min.js"></script>
    <script type="text/javascript" language="javascript" src="buttons.flash.min.js"></script>
    
  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin

    There must be a difference between the files on your local server and those on the CDN is all I can really say, or the paths to them are wrong. But without being able to access the page, I honestly can't say.

    Allan

  • Dmitriy5Dmitriy5 Posts: 1Questions: 0Answers: 0
    edited December 2016

    Could be something to do with Flash fallback from HTML5 on IE. Is SWF file loaded on local server?

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin

    By default the SWF file is loaded form the CDN, although that can be modified using the $.fn.DataTable.Buttons.swfPath parameter.

    Allan

  • Worthy7Worthy7 Posts: 8Questions: 3Answers: 0

    I would like to add that with the current page at:
    https://datatables.net/extensions/buttons/examples/flash/simple.html

    All buttons work except the Excel button, which does absolutely nothing for me.

    I am using a brand new Windows XP with IE8 and flash installed. The excel button is MEGA broken.

  • Worthy7Worthy7 Posts: 8Questions: 3Answers: 0

    buttons 1.2.4 has a JS error in it for IE8

  • Worthy7Worthy7 Posts: 8Questions: 3Answers: 0

    I think it is that XMLSerializer is not defined in IE. For whatever reason.

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin

    brand new Windows XP

    Is there such a thing? ;-).

    Old versions of IE don't support the XMLSerializer - hence the issue. Thanks for the PR - will continue the discussion there.

    Allan

  • Neeraj24Neeraj24 Posts: 35Questions: 4Answers: 0

    The Code which was given above Export to Excel is not Working ,can anyone helpme out .

  • Neeraj24Neeraj24 Posts: 35Questions: 4Answers: 0










    $(document).ready(function() { $('#FlagsExport').DataTable({ "pageLength": 50, dom: 'Bfrtip', buttons: ['copy','csv','excel','pdf','print'] }); });
  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin

    @Neeraj24 - Please provide a link to a test case showing the issue, per the forum rules.

    Allan

  • Neeraj24Neeraj24 Posts: 35Questions: 4Answers: 0

    Check this @allan

  • Neeraj24Neeraj24 Posts: 35Questions: 4Answers: 0

    can anybody help me please............

  • kthorngrenkthorngren Posts: 21,270Questions: 26Answers: 4,935

    You page works for me. I'm able to export Excel and PDF. What is not working for you?

    Kevin

  • krishna_mauryakrishna_maurya Posts: 1Questions: 0Answers: 0

    How to show paging :10,25,50,100,500. And how to change the File Name for all.

This discussion has been closed.