Buttons extension included on page but buttons don't appear
Buttons extension included on page but buttons don't appear
I've added the Buttons extension on my page but depending on how I initialize, either no buttons are showing up or the table itself doesn't show up. Here's the code to initialize the table:
$(document).ready( function() {
dtHerbs = $('#tblHerbs').DataTable( {
ajax: 'sqlprocs.asp?proc=getherbs',
dom: '<"top"Bif>rt<"bottom"lp><"clear">',
render: $.fn.dataTable.render.number( ',', '.', 2),
paging: true,
pageLength: 25,
pagingType : 'full_numbers',
select: {style: 'single'},
buttons: [ 'print', 'pdf', 'copy' ],
columnDefs: [ {
targets: 6,
data: null,
width: '40px',
defaultContent: '<image src=edit.png title="Edit" class=editherb_png> <image src=delete.png title="Delete" class=deleteherb_png>'
} ]
});
When I locate the table as shown above, by using the B within the dom option, the table itself isn't displayed except for the headers, and the rest of my JS code doesn't execute resulting in a garbled page. I tried removing the B and locating the table using this code.
dtHerbs.buttons().container()
.appendTo( $('.col-sm-6:eq(0)', dtHerbs.table().container() ) );
In that case the page displays correctly, but there are no buttons. The debugger doesn't show any errors so I don't understand what's happening here.
This question has an accepted answers - jump to answer
Answers
Did you include both the css and the js?
Yes I did.
Typically when the buttons to appear all the required JS files are not included. This page lists the required JS files needed for each button:
https://datatables.net/download/release#Buttons
You also need to make sure to include the two PDFMake JS for the PDF button.
Kevin
I added the files for print and PDF (pdfmake.min.js, vfs_fonts.js). The print button now appears but the PDF doesn't, and neither does the copy button, which doesn't appear to require any additional files.
Can you show us all of your <script> and <link> tags?
Here are the relevant tags, and my revised constructor.
EDIT: You also need to load either the flash or the html5 JS or both to support the type of buttons you want.
Kevin
Thanks, that made it work! I don't think the documentation makes this requirement clear at all.