TableTools buttons not working
TableTools buttons not working
I have been trying to implement DataTable table tools since last 2 days, but not getting any success. I have tried various forums, but no solution found so far which works for me.
Some observations:
- Buttons are displayed correctly
- Print, Select all, Select none button works fine
- Copy button says 0 rows selected
- PDF / CSV / Excel buttons do not respond at all.
In some forums, similar code is working perfectly fine, but not for me.
I am using these js files:
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://cdn.datatables.net/1.10.8/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.8/js/dataTables.bootstrap.min.js"></script>
<script src="https://cdn.datatables.net/responsive/1.0.7/js/dataTables.responsive.min.js"></script>
<script src="https://cdn.datatables.net/tabletools/2.2.4/js/dataTables.tableTools.js"></script>
And this is my table initialization:
dt = $('#MyDataTable').DataTable({
responsive: true,
"data": resultData,
"displayLength": 100, //-1 = All,
"lengthChange": false, // To show page size dropdown
"destroy": true,
"scrollX": false,
"scrollY": "400px",
"scrollCollapse": true,
"sortClasses": false,
"order": [[0, "desc"]],
"columns": seawdarasListColumnsData,
"columnDefs": [{
"targets": -1,
"data": null,
"render": function (data, type, row) {
var htmlText = '<span title="Click to mark attendance for this Sewadar"';
htmlText += 'class="btn btn-success btn-xs" >' + btnQuickAttendanceText + '</span>';
htmlText += ' <span title="Click to mark \'Manual\' attendance for this Sewadar"';
htmlText += 'class="btn btn-success btn-xs" >' + btnManualAttendanceText + '</span>';
htmlText += ' <span title="Click to see Attendance Report for this Sewadar"';
htmlText += 'class="btn btn-success btn-xs" >' + btnPersonAttendanceReportText + '</span>';
return htmlText;
}
}],
//select: true,
"dom": 'T<"clear">lfrtip',
"tableTools": {
"sSwfPath": "https://cdn.datatables.net/tabletools/2.2.4/swf/copy_csv_xls.swf"
}
});
This was my initial code. I found from somewhere this piece of code, but this also didn't help me.
"tableTools": {
"sSwfPath": "https://cdn.datatables.net/tabletools/2.2.4/swf/copy_csv_xls.swf",
"sRowSelect": "os",
"sRowSelector": 'td:first-child',
"aButtons": [
"copy",
"csv",
"xls",
{
"sExtends": "pdf",
"fnCellRender": function (sValue, iColumn, nTr, iDataIndex) {
//extract the value of the select
if (iColumn === 7) {
var val = $(sValue).find('select').val();
return (val !== '') ? val : 'not set';
}
//create a dummy text for the HTML-link
if (iColumn === 8) {
return 'click';
}
return sValue;
}
},
"print",
"select_all",
"select_none"
]
}
I really need to sort this out as my complete project is setup now. i just need to have these export features so that I can deliver my project.
For your convenience, I have also created a jsbin here:
Answers
jsbin for the same:
https://jsbin.com/fihixakeba
Most of the actual browsers won't support flash anymore, which is needed for the TableTools extension. you should try to implement the html5 logic to your dataTables.
see here: https://datatables.net/extensions/buttons/
This works fine for me.
@Widar, Can you give me a working example?
Thanks
https://datatables.net/extensions/buttons/examples . It is int he "Examples" section of the documentation that Widar links to.
I'm not sure why your TableTools example isn't working - I've never been able to get TableTools to work in JSBin for some reason. If you have a direct link to the page you are working on I can take a look, or you could use Buttons as Widar suggests.
Allan
URL:
http://skrm001.tarunsuneja.com/PersonDetail
Super - thank you. It would appear that Flash is throwing a security warning:
The short term fix is to install the SWF on your own server and use it locally. That will address that issue directly.
I'll look into a proper fix - I'm fairly sure that this has been addressed in the Flash export buttons for Buttons already, but I'll look into back porting it for TableTools.
Thanks again for the link.
Allan
@Allan,
swf file is rendering correctly for me. There are some flash settings need to be done on browser level. So, probably, you need that.