问题
I've been struggling with this for two days. I've posted on the datatables forum but I've gotten no response so I'm hoping the community here can help. I've read similar posts on this issue here but I'm already using the correct path for sSwf as many posts suggest.
The export buttons appear and all resources are loaded. However, Clicking the buttons has no action. There are no errors on the console.
<script>
$(document).ready(function() {
$('#example').DataTable( {
dom: 'T<"clear">lfrtip',
tableTools: {
"sSwfPath": "http://cdn.datatables.net/tabletools/2.2.2/swf/copy_csv_xls_pdf.swf"
}
} );
} );
</script>
Here is a JSFiddle with my code: http://jsfiddle.net/h2bof5cr/2/
回答1:
Your code is correct and matches the TableTools example. The issue is related to loading external SWF file, it doesn't work when code is loaded in <iframe>
(as in your JSFiddle example) or when loaded from file on your computer using file://
protocol due to security restrictions.
The solution is to upload your code to a web server and it should work without any changes.
Alternatively, if you want it to work locally on your computer, you need to use relative path to copy_csv_xls_pdf.swf
. For example save copy_csv_xls_pdf.swf
along with your page and use "sSwfPath": "copy_csv_xls_pdf.swf"
.
来源:https://stackoverflow.com/questions/29877651/tabletools-export-in-jquery-datatables-not-working