Thomas Johnson Thomas Johnson - 4 months ago 27
Javascript Question

Call DataTables export functions from JavaScript

The DataTables buttons extension allows users to export the table data to CSV, Excel, etc. There are examples in the documentation that show how to style the button elements.

What I want to do though is to be able to call the export functions from menu buttons in a Floating Action Button. I could move and restyle the DataTables buttons every time the data table gets redrawn, but is there an easier way?

In particular, is there a way to call the export functions directly from JavaScript?

Answer

Couple what @DelightedD0D said in his comment:

You could always just do

$('#floatingBtn').click(function(){ $('#someExportBtn').click(); });

... with some CSS to force the original buttons out of view off-screen and you'd wind up with only one set of buttons being shown.

.buttons-html5, .buttons-print {
    position: absolute;
    left: -9999px;
}