I am using bootstrap v4.2.1 and datatables v1.10.19 with the buttons extension. I'm trying to group together my "export" buttons (csvHtml5 and excelHtml5) in a collection using the following:
var data = $('#data').DataTable({
dom: 'Bfrtip',
buttons: [
{
extend: 'collection',
className: 'btn btn-outline-success dropdown-toggle',
text: 'Export',
buttons: [
{
extend: 'csvHtml5',
className: 'dropdown-item'
},
{
extend: 'excelHtml5',
className: 'dropdown-item'
}
]
},
{
extend: 'print',
className: 'btn btn-outline-success'
}
]
});
The problem that I'm running into is that the dropdown isn't being displayed correctly. My guess is that because the parent <div> that the dropdown items are being displayed in does not have the dropdown-menu class. So to correct this I added the following after initializing the datatable:
$('.dropdown-toggle').on('click', function() {
$('.dropdown-item').parent().addClass('dropdown-menu');
});
This works, only now the dropdown items are displayed for a second and then they disappear.
My first question is: am I setting this up right? My second question is: if not, then how do I setup the datatable collection to look like the bootstrap dropdown?
UPDATE
Something that I noticed after making this post is that if I click on my print button before I click on the export button then the dropdown items stay showing up as expected.