jQuery Plugin To Export Table To Other Document Types - tableExport

File Size: 12.1 KB
Views Total: 15334
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
jQuery Plugin To Export Table To Other Document Types - tableExport

tableExport is a lightweight yet customizable jQuery plugin for exporting your html table to other types of documents: CSV, XLS, TXT, SQL and JSON(new). You can specify which table columns to export. Custom filename and head/column delimiters are supported as well.

How to use it:

1. Include jQuery library and the jQuery tableExport plugin on the webpage as usual.

<script src="//code.jquery.com/jquery.min.js"></script>
<script src="tableExporter.js"></script>

2. Create a list of links to export your html table to specified document types.

<ul>
  <li><a onclick="exportTo('csv');" href="javascript://">CSV</a></li>
  <li><a onclick="exportTo('txt');" href="javascript://">TXT</a></li>
  <li><a onclick="exportTo('xls');" href="javascript://">XLS</a></li>
  <li><a onclick="exportTo('sql');" href="javascript://">SQL</a></li>
  <li><a onclick="exportAll('json');" href="javascript://">JSON</a></li>
</ul>

3. Initialize the plugin with default options.

function exportTo(type) {

  $('.table').tableExport();

}

4. Customize the file name.

function exportTo(type) {

  $('.table').tableExport({

    // table_26-05-2016
    filename: 'table_%DD%-%MM%-%YY%'
  });

}

5. Select specific columns to export.

function exportTo(type) {

  $('.table').tableExport({

    cols: '2,3,4'
    
  });

}

6. Customize the separators for titles and columns when exporting

function exportTo(type) {

  $('.table').tableExport({

    cols: '',
    head_delimiter: ';',

  });

}

7. Callback functions.

function exportTo(type) {

  $('.table').tableExport({

    onbefore: function(t){},
    onafter: function(t){}

  });

}

Change logs:

2018-01-08

  • Added support for quoting csv

2017-12-01

  • add JSON exporting. fix bugs. formatting code

2017-11-26

  • Fix utf-8 encoding for excel files

2017-01-16

  • Fixed examples, add Bower.json and etc.

2016-12-01

  • Fixed code, so that the date parsing function is working

2016-11-29

  • fixed for firefox

This awesome jQuery plugin is developed by Archakov06. For more Advanced Usages, please check the demo page or visit the official website.