jQuery Plugin To Export Table – Table Export

File Size:3.31 KB
Views Total:358
Last Update:December 31, 2017
Publish Date:December 30, 2017
Official Website:Go to website
License:MIT

It is a lightweight and the designed jquery plugin for the exporting your HTML to the other kinds of the documents such as CSV, XLS, TXT, SQL and JSON is known as table export. By this specification we can specify which table columns are to be exported. In this custom file names are supported as well.

How to use it:

1. Include jQuery library and the jQuery tableExport plugin :

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

<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>
<span class="html-tag" style="font-family: monospace; font-size: medium; white-space: pre-wrap;">  <li></span><span class="html-tag" style="font-family: monospace; font-size: medium; white-space: pre-wrap;"><a <span class="html-attribute-name">onclick</span>="<span class="html-attribute-value">exportAll('json');</span>" <span class="html-attribute-name">href</span>="<a class="html-attribute-value html-external-link" target="_blank">javascript://</a>"></span><span style="font-family: monospace; font-size: medium; white-space: pre-wrap;">JSON</span><span class="html-tag" style="font-family: monospace; font-size: medium; white-space: pre-wrap;"></a></span><span class="html-tag" style="font-family: monospace; font-size: medium; white-space: pre-wrap;"></li></span>
</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 :

function exportTo(type) {

  $('.table').tableExport({

    cols: '',
    head_delimiter: ';',

  });

}

7. Callback functions :

function exportTo(type) {

  $('.table').tableExport({

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

  });

}

Done ūüôā

Change Log

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