Plug-ins

This extension has now been retired and has been replaced by the Buttons and Select extensions. The documentation is retained for legacy reference only. New projects should use Buttons and Select in preference to TableTools.

Plug-ins for TableTools take the form of new button definitions. These button types can be included in your Javascript and then used by TableTools using the normal initialisation methods for selecting which buttons to use (aButtons).

If you have created any button types yourself and would like to share them, please get in touch and send me your plug-in so I can put it up on this page!

Plug-in buttons

copy_to_div
Show details
This button will copy the table contents (in formatted text, rather than HTML) to an element with a given ID (using the 'sDiv' parameter).
Author: Allan Jardine
Code: $.fn.dataTable.TableTools.buttons.copy_to_div = $.extend( true, {}, $.fn.dataTable.TableTools.buttonBase, { "sNewLine": ">br<", "sButtonText": "Copy to element", "target": "", "fnClick": function( button, conf ) { $(conf.target).html( this.fnGetTableData(conf) ); } } ); /* Example usage */ $(document).ready( function () { $('#example').dataTable( { dom': 'T<"clear">lfrtip', tableTools': { "aButtons": [ { "sExtends": "copy_to_div", "sButtonText": "Copy to div", "target": "#copy", } ] } } ); } );
download
Show details
This button will create a form that is submitted to the server when the button is activated. It can be configured to use GET or POST (using the `sType` option) and the request URL is defined the `sUrl` option. This is ideal for making a request to the server that will trigger a download, for example creating a PDF using a server-side processing.

The plug-in will submit the same parameters as DataTables uses for its own Ajax request (for example server-side processing parameters) if Ajax data is enabled in DataTables. The data submitted is available in the HTTP variable `json` and is a JSON encoded representation of the data. The `fnData` option can be specified to add additional parameters to the data object if required.

Note that this plug-in requires DataTables 1.10 or newer.
Author: Allan Jardine
Code: $.fn.dataTable.TableTools.buttons.download = $.extend( true, {}, $.fn.dataTable.TableTools.buttonBase, { "sButtonText": "Download", "sUrl": "", "sType": "POST", "fnData": false, "fnClick": function( button, config ) { var dt = new $.fn.dataTable.Api( this.s.dt ); var data = dt.ajax.params() || {}; // Optional static additional parameters // data.customParameter = ...; if ( config.fnData ) { config.fnData( data ); } var iframe = $('<iframe/>', { id: "RemotingIFrame" }).css( { border: 'none', width: 0, height: 0 } ) .appendTo( 'body' ); var contentWindow = iframe[0].contentWindow; contentWindow.document.open(); contentWindow.document.close(); var form = contentWindow.document.createElement( 'form' ); form.setAttribute( 'method', config.sType ); form.setAttribute( 'action', config.sUrl ); var input = contentWindow.document.createElement( 'input' ); input.name = 'json'; input.value = JSON.stringify( data ); form.appendChild( input ); contentWindow.document.body.appendChild( form ); form.submit(); } } ); // Example initialisation $(document).ready( function () { $('#example').dataTable( { "sDom": 'T<"clear">lfrtip', "oTableTools": { "aButtons": [ { "sExtends": "download", "sButtonText": "Download XLS", "sUrl": "/generate_xls.php" } ] } } ); } );