HTML5 export buttons
HTML5 export buttons
Perdido
Posts: 5Questions: 2Answers: 0
Hello
I'm trying use initialise javascript to create buttons:
$(document).ready(function () {
$('#tblReportWorkerActivity').DataTable({
retrieve: true,
dom: 'Bfrtip',
buttons: [
'copyHtml5',
'excelHtml5',
'csvHtml5',
'pdfHtml5'
]
});
});
But I don't know how doesn't work !
Maybe will be know where is my problem.
Best regards Dawid
This discussion has been closed.
Replies
Maybe I need css file and js file in my project ? but which ?
Now i use:
- datatable.js
- buttons.html5.js
Maybe in this is problem ?
Maybe can you help me ? :)
I got most of the html5 buttons working with the old version of datatables (I had a couple of issues when I used the new datatables and editor so I just decided to get the html5 buttons working with the older version):
You need the following in the head of your html:
For css I just added this:
These files can all be downloaded from 'https://datatables.net/download/index'.
All the buttons work perfectly except for Print (which I will have a play around with). I also didn't use CSV as Excel is working well (and I may have also had a small issue with CSV with the old datatables). Here are my button settings (note 'reportTitle' is a variable that contains the name and description for my report):
A tip about the PDF export. I found that the columns were not autospaced so it didn't look good if you only had three or four columns. I looked at the very well documented 'pdfmake.js' site and added this line to Allan's 'buttons.html5.sj' line 632:
This changes the code to:
and spaces all of the columns beautifully.
I will have a try plugging in the new versions of datatables and editor in a few days but I hope this helps. As I say 'Print' needs a little work so you might want to leave that out for now.
For others - don't forget that you have to use B instead of T in the 'dom' setting (Perdido has done this correctly)
If you have any feedback on the issues you are having with the print button, they would be very welcome.
Allan
Ok in my solution problem was in html initialization where I used attribute data-role="dataTable". I remove this attribute and add dataTable to class.
Now it work very nice :)
Thank you very much !