To use this plugin, include the jQuery library, FileSaver.js script, and [TableExporter.js] plugin before the closing <body>
tag of your HTML document:
<script src="jquery.js"></script>
<script src="filesaver.js"></script>
<script src="tableexporter.js"></script>
...
$ bower install table-exporter
- jQuery (1.2.1 or higher)
- FileSaver.js
In order to provide Office Open XML SpreadsheetML Format ( .xlsx ) support, you must include the following third-party script to your project before FileSaver.js and TableExporter.
- SheetJS -> xlsx-core.js
<script src="xlsx-core.js"></script>
<script src="filesaver.js"></script>
...
<script src="tableexporter.js"></script>
To use the export plugin, just call:
$("table").tableExport({format: '<type>'}); //Format of file eg. txt, csv, xls, xlsx
var html = ($().convertJsonToHtml(<JsonObj>);
$(html).tableExport({format:'<type>'});
Options
simple option
var options = ['<fieldName>']; //name of field fron json object
advanced options
var options = [{fieldName: '<fieldName>', columnName: '<columnName>', type: '<type>'}]; //name of field from json object, column name alias (optional), object type (optional)
object type options: string, number, date;
advanced advanced options
var options = [{ fieldName: '<fieldName>', type: '<type>', options:[{fieldName: '<fieldName>', columnName: '<columnName>'}]; // this if for json objects with nested arrays
| Property | Description | Values | Optional | | :------: | :------: | :-------: | :---: | :-----: | :------: | | fieldName | Json object field name | string | yes| | columnName | Column alias name | string | yes | | type | data type | string, number, date | yes | | options | wololo | object | yes |
Example
var options = ['<fieldName>']; //name of field fron json object
var data = JSON.stringify(<data>);
var html = $().convertJsonToHtml(data,options);
$(html).tableExport({format: 'xlsx'});
Additional properties can be passed in to customize the look and feel of your tables, buttons, and exported data.
Note: to use the xlsx filetype, you must include the third-party scripts listed in the Dependencies section.
TableExport supports additional methods (update, reset and remove) to control it after creation.
/* Run plugin and save it to a variable */
var tables = $("table").tableExport();
/* update */
tables.tableExport.update({
filename: "newFile" // pass in a new set of properties
});
/* reset */
tables.tableExport.reset(); // useful for a dynamically altered table
/* remove */
tables.tableExport.remove(); // removes caption
| Property | Description | Values | Default | | :------: | :------: | :-------: | :---: | :-----: | :------: | | formats | filetype to export | string | wololo | | filename | filename for exported file | wololo | wololo | | ignoreRows | wololo | wololo | wololo | | ignoreCols | wololo | wololo | wololo |
Chrome | Firefox | IE * | Opera | Safari | |
---|---|---|---|---|---|
Android * | ✓ | ✓ | - | ✓ | - |
iOS * | ✓ | - | - | - | ✓ |
Mac OSX | ✓ | ✓ | - | ✓ | ✓ |
Windows | ✓ | ✓ | ✓ | ✓ | ✓ |
*requires third-party dependencies
- [Clarke Travis] (https://www.clarketravis.com/tableexport/) - tableexport
- John Resig - jQuery
- SheetJS - js-xlsx
- Eli Grey - FileSaver.js & Blob.js
This is a cloned project from https://www.clarketravis.com/tableexport/