How to display Datatable tabletools (copy, csv, excel, pdf, save) in ruby ​​on rails

I am using Datatable in my ruby ​​on rails application. I follow the same one here ..

https://github.com/rweng/jquery-datatables-rails

And my data sorting and search work correctly. But I do not see my table tool option (for example, - copy, csv, excel, pdf, save) in the table header.

I want to show my table like this ....

enter image description here

Please help.

+7
source share
2 answers

Update (2016):

Although they fire TableTools for the Button and Select extensions ( source ), this is a slightly newer version of the dom example:

var oTable = $('#my-table').dataTable({ autoWidth: false, autoHeight: false, paging: false, dom: 'TCfrtip', // <-- Update letters for whichever extensions you want to use responsive: false, searching: true, ordering: true, stateSave: true, scrollY: 550, scrollX: true, scrollCollapse: true, fixedHeader: false, buttons: [ 'copyHtml5', 'csvHtml5', 'excelHtml5', 'pdfHtml5' ], columnDefs: [{ targets: 'no-sort', // disable sorting on class="no-sort" orderable: false }], drawCallback: function (settings) { } }); 

Previous Answer (2013):

The solution is to add this:

"sDom": '<"H"TCfr>t<"F"ip>'

Inside your javascript. It will also work with show / hide columns. If you do not use show / hide columns, you can remove the capital "C".

Example (with show / hide columns):

 // Users $("#users-datatable").dataTable({ "bStateSave": true, "bJQueryUI": true, "sPaginationType": "full_numbers", "bProcessing": true, "bServerSide": true, "sAjaxSource": $('#users-datatable').data('source'), "bScrollInfinite": true, "bScrollCollapse": true, "iDisplayLength": 100, "sScrollY": "500px", "sScrollX": "100%", "sDom": '<"H"TCfr>t<"F"ip>', "oTableTools": { "aButtons": [ "copy", "csv", "xls", { "sExtends": "pdf", "sPdfOrientation": "landscape", "sPdfMessage": "Your custom message would go here." }, "print" ] } }); 

Hope this helps someone.

0
source

I got this by adding ZeroClipboard.js

 <script src="http://localhost/assets/js/ZeroClipboard.js"></script> 
0
source

All Articles