Buttons don't display when ajax is used to populate table
Buttons don't display when ajax is used to populate table
Buttons are visible and functional if I comment out my "ajax" parameter, but with the ajax parameter, the buttons are missing. I can manually get them to appear after the ajax table loads by manually calling table.buttons().container().appendTo( $('#tableButtons') ); in Chrome's js console.
table = $('#allMaltTable').DataTable( {
"ajax": "/someurl",
"columns": [
...
],
buttons: [
'colvis', 'excelHtml5', 'csvHtml5', 'copyHtml5'
]
} );
table.buttons().container().appendTo( $('#tableButtons') );
I suspect that table.buttons().container() is not initialized early enough for use with ajax.
I'm using a Download Builder provided version of DataTables-1.10.11, and jquery 2.1.1, and some other libraries if it matters.
How should I be setting up the buttons when using an ajax data source?
This discussion has been closed.
Answers
You need to move the API call into
initComplete. The ajax call makes the table initialisation async.Allan