TableTools on jQuery DataTables

Posted: August 15, 2011 in PHP, Programming
Tags: , , ,

DataTables is a jQuery plugin to visualize table that is pretty much awesome and has lot of features. Now, I want to talk about TableTools, an extension which has function to export data into files such as CSV, Excel, or PDF.  Here’s a screenshot:

The configuration of TableTools is pretty much easy, you just need litte additional code onto DataTables javascript code:

$('#mytable').dataTable({
    "sDom": 'Tlfrtip',
    "oTableTools": {
    "sSwfPath": "<!--?php echo $this--->config->item('base_url');?>application/libraries/jQuery/plugins/DataTables-1.8.1/media/swf/copy_cvs_xls_pdf.swf"
    }
});

Code at above, mytable is id of your table, and you should add “sDom”: ‘Tlfrtip’ for DataTables DOM display’s configuration, and the last (and the most important), add “sSwfPath”: “yourpath/copy_cvs_xls_pdf.swf”.

Notice the sSwfPath has absolute value (On the code above, i used CodeIgniter).  If you don’t specify this path correctly, TableTools won’t work.

Comments
  1. hi, i am working in ASP.NET and using datatable. here is the code i wrote.

    $(‘#reportDetailListGridViewTbl’).dataTable({
    “sDom”: ‘Tt’,
    “oTableTools”: {
    “sSwfPath”: “../../Templates/JS/datatables/copy_csv_xls_pdf.swf”,
    “aButtons”: [
    “copy”,
    “xls”,
    “print”
    ]
    },
    “bJQueryUI”: true,
    “sPaginationType”: “full_numbers”,

    its showing Copy, Excel, Print button but not working.
    TableTools.js and copy_csv_xls_pdf.swf files are in the same folder. but still when i click on Excel button nothing happened. what is my fault?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s