<< Examples

ExportButtons exportButtons: false



Name Position Age Salary
Thor Walton Regional Director 45 $98,540
Travis Clarke Software Engineer 30 $275,000
Suki Burks Office Manager 22 $67,670
$441,210

Your own custom export button can be easily created by simply capturing the TableExport instance.
  1. First, save the TableExport instance to a variable.
  2. Second, call getExportData() on the instance from step 1. The return value will be an object literal with keys corresponding to the table selector(s) id attribute (or a unique uuid generated by TableExport if an id is not provided).
  3. Lastly, call export2file(data, mimeType, filename, fileExtension). The arguments correspond to the keys of the Object returned from step 2 above.
First, in a variable

var ExportButtons = document.getElementById('export-buttons-table');

var instance = new TableExport(ExportButtons, {
    formats: ['xls'],
    exportButtons: false
});

//                                        // "id" of selector    // format
var exportData = instance.getExportData()['export-buttons-table']['xls'];

var XLSbutton = document.getElementById('customXLSButton');

XLSbutton.addEventListener('click', function (e) {
    //                   // data          // mime              // name              // extension
    instance.export2file(exportData.data, exportData.mimeType, exportData.filename, exportData.fileExtension);
});

Additionally, the raw binary data (and byte length) can be retrieved using the getBinaryData prototype method.
// get raw binary data (i.e. filesize)
var bytes = TableExport.prototype.getBinaryData(exportData.data, exportData.fileExtension);
var byteLength = bytes.byteLength;