TableTools not working with JQuery UI Accordion
TableTools not working with JQuery UI Accordion
Taylor514ce
Posts: 74Questions: 8Answers: 0
I have three tabs, each tab has three accordions, and the bottom accordion in each will contain a datatable.
I started with just a basic HTML containing only a single datatable, and got it working correctly.
I added Tabs, all still good.
But when I add accordion, the TableTools buttons stop working. I've seen various threads on this issue but have not found a clear, repeatable solution.
I started with just a basic HTML containing only a single datatable, and got it working correctly.
I added Tabs, all still good.
But when I add accordion, the TableTools buttons stop working. I've seen various threads on this issue but have not found a clear, repeatable solution.
This discussion has been closed.
Replies
[code]
$(document).ready(function() {
myTable = $('#box-table-a').dataTable( {
"bProcessing": false,
"bJQueryUI": true,
"sDom": '<"H"f>t<"F">T',
"sScrollY": "410px",
"sAjaxSource": "http://<!--SERVERURL-->/formatLog.txt",
"bPaginate": false,
"bFilter": true,
"bAutoWidth": false,
"aoColumns": [null, null, null, { "sWidth": "80%" }, {"bVisible": true} ],
"aaSorting": [[4,'desc']],
"oTableTools": {
"sSwfPath": "http://<!--SERVERURL-->/loadTableTools",
"aButtons": [ "copy","csv","xls",
{
"sExtends": "pdf",
"sPdfOrientation": "landscape",
"sPdfMessage": "PlanetPress Activity Log"
},"print"]
}
} );
// Accordion
$("#accordion").accordion({ header: "h3", active: 0, autoHeight: false });
// Tabs
$('#tabs').tabs();
} );
[/code]
Everything displays correctly, but the TableTools Flash buttons do not hover or trigger any events. If I remove the Accordion, they work correctly, so I know my SWF path is correct. I can paste my complete markup if required.
http://datatables.net/extras/tabletools/api#fnResizeButtons
[code]
$(document).ready(function() {
myTable = $('#box-table-a').dataTable( {
"bProcessing": false,
"bJQueryUI": true,
"sDom": '<"H"f>t<"F">T',
"sScrollY": "410px",
"sAjaxSource": "http://<!--SERVERURL-->/formatLog.txt",
"bPaginate": false,
"bFilter": true,
"bAutoWidth": false,
"aoColumns": [null, null, null, { "sWidth": "80%" }, {"bVisible": true} ],
"aaSorting": [[4,'desc']],
"oTableTools": {
"sSwfPath": "http://<!--SERVERURL-->/loadTableTools",
"aButtons": [ "copy","csv","xls",
{
"sExtends": "pdf",
"sPdfOrientation": "landscape",
"sPdfMessage": "PlanetPress Activity Log"
},"print"]
}
} );
// Accordion
//$("#accordion").accordion({ header: "h3", active: 0, autoHeight: false });
$("#accordion").accordion( {
header: "h3", active: 0, autoHeight: false,
"show": function(event, ui) {
var jqTable = $('table.display', ui.panel);
if ( jqTable.length > 0 ) {
var oTableTools = TableTools.fnGetInstance( jqTable[0] );
if ( oTableTools != null && oTableTools.fnResizeRequired() )
{
jqTable.dataTable().fnAdjustColumnSizing();
oTableTools.fnResizeButtons();
}
}
}
} );
// Tabs
$('#tabs').tabs();
} );
[/code]
But this has no effect. The flash buttons show but do not function.
If I set the page so that the accordion holding the datatable is active, so that the datatable is visible on initial load, the Flash buttons in the TableTools work.
It's only when that table is hidden (either initially or through expanding and collapsing the accordion), the buttons fail.
So we're on the right track, but I cannot find the correct event to code. I tried "changestart" instead of "show" and will keep looking, but wanted to post in the hopes someone has already solved the issue and wants to share the solution.
Thanks.
[code]
$("#tabs").tabs( {
"show": function(event, ui) {
var jqTable = $('table.display', ui.panel);
if ( jqTable.length > 0 ) {
var oTableTools = TableTools.fnGetInstance( jqTable[0] );
if ( oTableTools != null)
{
jqTable.dataTable().fnAdjustColumnSizing();
oTableTools.fnResizeButtons();
}
}
}
} );
[/code]
The line: var jqTable = $('table.display', ui.panel);
That finds the Datatable within the ui.panel created by the Tab, but if the Tab contains an Accordion, and the Accordion contains the Datatable, what change would I make to find the table?
[code]
$("#accordion").accordion( {
"change": function(event, ui) {
var jqTable = $('table.display', ui.newContent);
if ( jqTable.length > 0 ) {
var oTableTools = TableTools.fnGetInstance( jqTable[0] );
if ( oTableTools != null)
{
jqTable.dataTable().fnAdjustColumnSizing();
oTableTools.fnResizeButtons();
}
}
}
} );
[/code]
However, this still doesn't find the datatable... jqTable.length remains "0".
http://bay13box.com/datatables/test.htm
The datatables table is in tab 2 at the bottom. Works for me. You should be able to figure out your own implementation from the source.
This line:
[code]
var jqTable = $('table.display', ui.panel);
[code]
Simply doesn't work for me... FireBug shows [], an unnamed object with length = 0
When I alter to use my global variable for the specific table:
[code]
var jqTable = myTable;
[code]
It of course works, but that isn't dynamic. If I have multiple tabs/accordions/tables, I need the event function to resolve to just that accordion's table. I see your example and of course it works, but I'm not sure what the difference might be, other than that you haven't assigned your datatable to a global variable.
I don't know why it would work in my example but not on yours. Can you post up a link at all to mess with?
Weird. It works in Chrome. I didn't try it in Firefox or IE but it appears it does not work properly in either of those browsers. Let me see if I can fix it.
The destroy / create example is here: http://bay13box.com/datatables/test.htm
Dialog Error when trying to display table:
[quote]DataTables warning (table id = 'DataTables_Table_1):
Cannot reinitialise DataTable.
To Retrieve the DataTables object for this table, pass no arguments or see the docs for bRetrieve and bDestroy[/quote]
JQuery code:
[code]
QueryDataTable').dataTable( {
"sDom" : 'T<"clear">lfrtip',
"oTableTools" : {
"sSwfPath" : "cms/swf/copy_cvs_xls_pdf.swf"
}
});
$('#accordionProduct').accordion( {
change : function(event, ui) {
oTable.fnDestroy();
oTable = $('.slimJQueryDataTable').dataTable( {
"sDom" : 'T<"clear">lfrtip',
"oTableTools" : {
"sSwfPath" : "cms/swf/copy_cvs_xls_pdf.swf"
}
});
}
});
[/code]