SimonSch / TableExporter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting Started

Download and Setup

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>
...

Install with Bower

$ bower install table-exporter

Dependencies

Required:
Add-Ons:

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.

<script src="xlsx-core.js"></script>
<script src="filesaver.js"></script>
 ...
<script src="tableexporter.js"></script>

Usage

JavaScript

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

Properties

| 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 |

Methods

Browser Support

Chrome Firefox IE * Opera Safari
Android * - -
iOS * - - -
Mac OSX -
Windows

*requires third-party dependencies

Credits

This is a cloned project from https://www.clarketravis.com/tableexport/

About

License:MIT License


Languages

Language:JavaScript 100.0%