TableTools Buttons only work on the first DataTable
TableTools Buttons only work on the first DataTable
iandawg
Posts: 8Questions: 0Answers: 0
http://debug.datatables.net/ahizel
I have a page that initializes two DataTables using this code:
[code]
$('#FedExSalesOverview').dataTable({
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"sSwfPath": "../../Content/TableTools-2.0.0/media/swf/copy_cvs_xls_pdf.swf"
},
...
$('#FedExSalesDetails').dataTable({
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"sSwfPath": "../../Content/TableTools-2.0.0/media/swf/copy_cvs_xls_pdf.swf"
},
...
[/code]
Both use supply the same value for the "oTableTools" parameter. The "copy", "csv", "Excel", "PDF" and "Print" buttons work on the first table ('#FedExSalesOverview'). The buttons appear, but don't do anything on the second table ('#FedExSalesDetails'). Both tables have Sort, Search and other features enabled, and those features work on both tables.
There's an error in the JS console : "uncaught exception: Unable to load SWF file - please check the SWF path"
I've tried to Initialize TableTools "globally" and then apply the tools using sDom, but I don't quite understand how this method works - I just read another blog post about this issue (http://datatables.net/forums/discussion/3963/tabletools-on-multiple-tables/p1) When I do this, I get the same result :
[code]
$(document).ready(function () {
TableTools.DEFAULTS.aButtons = ["copy", "csv", "xls", "pdf"];
TableTools.DEFAULTS.sSwfPath = "../../Content/TableTools-2.0.0/media/swf/copy_cvs_xls_pdf.swf";
$("#tabs").tabs();
$('#FedExSalesOverview').dataTable({
"bJQueryUI": true,
"sDom": '<"H"Tfr>t<"F"ip>',
...
[/code]
As you can see, I'm using jQuery.tabs() and I have the HTML for the DataTables on separate tabs.
I have a page that initializes two DataTables using this code:
[code]
$('#FedExSalesOverview').dataTable({
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"sSwfPath": "../../Content/TableTools-2.0.0/media/swf/copy_cvs_xls_pdf.swf"
},
...
$('#FedExSalesDetails').dataTable({
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"sSwfPath": "../../Content/TableTools-2.0.0/media/swf/copy_cvs_xls_pdf.swf"
},
...
[/code]
Both use supply the same value for the "oTableTools" parameter. The "copy", "csv", "Excel", "PDF" and "Print" buttons work on the first table ('#FedExSalesOverview'). The buttons appear, but don't do anything on the second table ('#FedExSalesDetails'). Both tables have Sort, Search and other features enabled, and those features work on both tables.
There's an error in the JS console : "uncaught exception: Unable to load SWF file - please check the SWF path"
I've tried to Initialize TableTools "globally" and then apply the tools using sDom, but I don't quite understand how this method works - I just read another blog post about this issue (http://datatables.net/forums/discussion/3963/tabletools-on-multiple-tables/p1) When I do this, I get the same result :
[code]
$(document).ready(function () {
TableTools.DEFAULTS.aButtons = ["copy", "csv", "xls", "pdf"];
TableTools.DEFAULTS.sSwfPath = "../../Content/TableTools-2.0.0/media/swf/copy_cvs_xls_pdf.swf";
$("#tabs").tabs();
$('#FedExSalesOverview').dataTable({
"bJQueryUI": true,
"sDom": '<"H"Tfr>t<"F"ip>',
...
[/code]
As you can see, I'm using jQuery.tabs() and I have the HTML for the DataTables on separate tabs.
This discussion has been closed.
Replies
That's the key bit - that in combination with the fact that you are using TableTools 2.0.0.
Basically the issue is that when TableTools is initialised it tries to size the Flash buttons to match the HTML buttons. But if the table is in a display:none element, as your second table in the tab is, then it has no dimensions and thus that will fail (or rather get 0x0).
The way to fix this is to call the fnResizeButtons API method ( http://datatables.net/extras/tabletools/api#fnResizeButtons ) when the tab is displayed (I think it's the 'show' event in jQuery UI).
Allan
The solution makes sense, but I can't get the oTableTools.fnResizeButtons(); function to work, (JS Console Error: oTableTools.fnResizeButtons is not a function). This is the code I used:
[code]
$("#tabs").tabs({
"show": function (event, ui) {
var table = $.fn.dataTable.fnTables(true);
if (table.length > 0) {
var oTableTools = TableTools.fnGetInstance(table[0]);
$(table).dataTable().fnAdjustColumnSizing();
if (oTableTools != null) {
alert("got an oTableTools object!");
oTableTools.fnResizeButtons();
alert("buttons should work");
} else {
alert("oTableTools == null");
}
}
}
});
[/code]
You can see that it is similar, though not identical to the code in the example you reference. I can see that I do get the oTableTools object, but the functions aren't bound to it.
Ian
http://debug.datatables.net/agawog
Allan
Allan
Allan
username: FXOReport
password: reports123
how would one apply the fix to a standard implimentation of table tools without jquery tabs, and first run the div is hidden?
thanks in advance
Allan
Allan
I don't know what I'm missing. I'm using nearly the exact code you mention in the answer on that other thread:
[code]
$("#tabs").tabs({
"show": function (event, ui) {
var table = $.fn.dataTable.fnTables(true);
if (table.length > 0) {
$(table).dataTable().fnAdjustColumnSizing();
var oTableTools = TableTools.fnGetInstance(table[0]);
if (oTableTools != null && oTableTools.fnResizeRequired()) {
oTableTools.fnResizeButtons();;
}
}
}
});
[/code]
I updated to the latest libraries (DataTables 1.9.4 and TableTools 2.1.4)