Docs
Getting Started
Install manually using <script>
tags
To use this library, include the FileSaver.js library, and TableExport library before the closing <body>
tag of your HTML document:
<script src="FileSaver.js"></script>
...
<script src="tableexport.js"></script>
Install with Bower
$ bower install tableexport.js
Install with npm
$ npm install tableexport
CDN
Dependencies
Required:
Optional:
Add-Ons:
In order to provide Office Open XML SpreadsheetML Format ( .xlsx
) support, you must include the following third-party library in your project before both FileSaver.js and TableExport.
Including xlsx.core.js
is NOT necessary if installing with Bower
or npm
<script src="xlsx.core.js"></script>
<script src="FileSaver.js"></script>
...
<script src="tableexport.js"></script>
Older Browsers:
To support legacy browsers ( Chrome < 20, Firefox < 13, Opera < 12.10, IE < 10, Safari < 6 ) include the Blob.js polyfill before the FileSaver.js script.
- Blob.js by eligrey (forked by clarketm)
Including Blob.js
is NOT necessary if installing with Bower
or npm
<script src="Blob.js"></script>
<script src="FileSaver.js"></script>
...
<script src="tableexport.js"></script>
Usage
JavaScript
To use this library, simple call the TableExport
constructor:
new TableExport(document.getElementsByTagName("table"));
TableExport(document.getElementsByTagName("table"));
$("table").tableExport();
Additional properties can be passed-in to customize the look and feel of your tables, buttons, and exported data.
Notice that by default, TableExport will create export buttons for three different filetypes xls
, csv
, txt
. You can choose which buttons to generate by setting the formats
property to the filetype(s) of your choice.
TableExport(document.getElementsByTagName("table"), {
headers: true,
footers: true,
formats: ['xlsx', 'csv', 'txt'],
filename: 'id',
bootstrap: false,
exportButtons: true,
position: 'bottom',
ignoreRows: null,
ignoreCols: null,
trimWhitespace: true
});
Note: to use the xlsx
filetype, you must include js-xlsx; reference the Add-Ons
section.
Properties
Methods
TableExport supports additional methods (getExportData, update, reset and remove) to control the TableExport
instance after creation.
var table = TableExport(document.getElementById("export-buttons-table"));
var exportData = table.getExportData();
var tableId = 'export-buttons-table';
var XLS = table.CONSTANTS.FORMAT.XLS;
var exportDataXLS = table.getExportData()[tableId][XLS];
var bytesXLS = table.getFileSize(exportDataXLS.data, exportDataXLS.fileExtension);
table.update({
filename: "newFile"
});
table.reset();
table.remove();
Settings
Below are some of the popular configurable settings to customize the functionality of the library.
TableExport.prototype.ignoreCSS = ".tableexport-ignore";
TableExport.prototype.ignoreCSS = [".tableexport-ignore", ".other-ignore-class"];
$.fn.tableExport.ignoreCSS = ".tableexport-ignore" ;
$.fn.tableExport.ignoreCSS = [".tableexport-ignore", ".other-ignore-class"] ;
TableExport.prototype.emptyCSS = ".tableexport-empty";
TableExport.prototype.emptyCSS = [".tableexport-empty", ".other-empty-class"];
$.fn.tableExport.emptyCSS = ".tableexport-empty" ;
$.fn.tableExport.emptyCSS = [".tableexport-empty", ".other-empty-class"];
TableExport.prototype.charset = "charset=utf-8";
TableExport.prototype.defaultFilename = "myDownload";
TableExport.prototype.defaultButton = "button-default";
TableExport.prototype.bootstrapConfig = ["btn", "btn-default", "btn-toolbar"];
TableExport.prototype.rowDel = "\r\n";
formatConfig: {
xlsx: {
defaultClass: 'xlsx',
buttonContent: 'Export to xlsx',
mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
fileExtension: '.xlsx'
},
xlsm: {
defaultClass: 'xlsm',
buttonContent: 'Export to xlsm',
mimeType: 'application/vnd.ms-excel.sheet.macroEnabled.main+xml',
fileExtension: '.xlsm'
},
xlsb: {
defaultClass: 'xlsb',
buttonContent: 'Export to xlsb',
mimeType: 'application/vnd.ms-excel.sheet.binary.macroEnabled.main',
fileExtension: '.xlsb'
},
xls: {
defaultClass: 'xls',
buttonContent: 'Export to xls',
separator: '\t',
mimeType: 'application/vnd.ms-excel',
fileExtension: '.xls',
enforceStrictRFC4180: false
},
csv: {
defaultClass: 'csv',
buttonContent: 'Export to csv',
separator: ',',
mimeType: 'text/csv',
fileExtension: '.csv',
enforceStrictRFC4180: true
},
txt: {
defaultClass: 'txt',
buttonContent: 'Export to txt',
separator: ' ',
mimeType: 'text/plain',
fileExtension: '.txt',
enforceStrictRFC4180: true
}
},
TableExport.prototype.formatConfig.xlsx.mimeType = "application/csv"
CSS
TableExport packages with customized Bootstrap CSS stylesheets to deliver enhanced table and button styling. These styles can be enabled by initializing with the bootstrap
property set to true
.
TableExport(document.getElementsByTagName("table"), {
bootstrap: true
});
When used alongside Bootstrap, there are four custom classes .xlsx
, .xls
, .csv
, .txt
providing button styling for each of the exportable filetypes.
Browser Support
| Chrome | Firefox | IE | Opera | Safari |
---|
Android | β | β | - | β | - |
iOS | β | - | - | - | β |
Mac OSX | β | β | - | β | β |
Windows | β | β | β | β | β |
A full list of browser support can be found in the FileSaver.js README. Some legacy browsers may require an additional third-party dependency: Blob.js
Examples
Customizing Properties
Customizing Settings
Miscellaneous
Skeletons
License
TableExport is licensed under the terms of the Apache-2.0 License
Going Forward
TODOs
Credits
Special thanks the the following contributors: