Datatables: Export buttons for CSV, Excel, and PDF not working
Datatables: Export buttons for CSV, Excel, and PDF not working
kofboat123
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?
This discussion has been closed.
Answers
Let me add that all the buttons work perfectly well in Google Chrome and Firefox but not IE.
@kofboat123,
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,
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>
It is working now, however, the Excel does not return any value at all when I save. The CSV button returns values.
We'd really need a link to a page showing the issue so it can be debugged please.
Thanks,
Allan
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
I have now switched to using the flash version hence the example I sent in the earlier post.
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
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.
What are you opening it with? If OpenOffice.org, then that is a known bug in OpenOffice.
Allan
No, I am opening it with Microsoft Excel 2013 or sometimes Excel 2016.
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
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?
I'm afraid I've no idea without being able to debug it :-). Perhaps try using the download builder.
Allan
When I use these, the page works, the way it is supposed to:
But when I host them locally, then nothing works...is there something I am supposed to do?
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
Could be something to do with Flash fallback from HTML5 on IE. Is SWF file loaded on local server?
By default the SWF file is loaded form the CDN, although that can be modified using the
$.fn.DataTable.Buttons.swfPath
parameter.Allan
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.
buttons 1.2.4 has a JS error in it for IE8
I think it is that XMLSerializer is not defined in IE. For whatever reason.
https://github.com/DataTables/Buttons/pull/116/commits/2497598ba5e63a5cc972449f2d4539cfe9ec4e9b
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
The Code which was given above Export to Excel is not Working ,can anyone helpme out .
$(document).ready(function() { $('#FlagsExport').DataTable({ "pageLength": 50, dom: 'Bfrtip', buttons: ['copy','csv','excel','pdf','print'] }); });@Neeraj24 - Please provide a link to a test case showing the issue, per the forum rules.
Allan
Check this @allan
can anybody help me please............
You page works for me. I'm able to export Excel and PDF. What is not working for you?
Kevin
How to show paging :10,25,50,100,500. And how to change the File Name for all.