Table Tools 2.0.1 - multiple tables, with each table inside a tab
Table Tools 2.0.1 - multiple tables, with each table inside a tab
mg
Posts: 47Questions: 0Answers: 0
I'm familiar with the Table Tools example showing multiple tables on a single page.
http://datatables.net/release-datatables/extras/TableTools/multiple_tables.html
(By the way, shouldn't the Initialisation code in the example grab the table by the
class name instead of the id name in order to work on multiple tables?)
And I'm familiar with the discussion of "Table Tools on multiple tables".
http://datatables.net/forums/comments.php?DiscussionID=3963
It doesn't seem to me that this problem has been resolved.
Here's how I'm encountering the problem at the moment.
I have 4 tables on a single page. When I show all the tables
at the same time, sure, the table tools buttons work for
each separate table, just like the example works.
However, once I put each table in its own separate "tab" div,
where the first tab is displayed when the page loads, and the
other three tabs are hidden until the tab links are clicked,
then the problems begin. The table in the first displayed
tab works: the table tools buttons can hover and can do print actions.
The tables in each of the hidden tabs, once they become the active tabs,
do NOT work. The button hover and the button clicking actions do nothing.
Has anyone come across this problem and found a fix for this?
The one forum posting shows a user had to resort to ajax to call each table,
and that seems pretty kludgy to me.
http://datatables.net/release-datatables/extras/TableTools/multiple_tables.html
(By the way, shouldn't the Initialisation code in the example grab the table by the
class name instead of the id name in order to work on multiple tables?)
And I'm familiar with the discussion of "Table Tools on multiple tables".
http://datatables.net/forums/comments.php?DiscussionID=3963
It doesn't seem to me that this problem has been resolved.
Here's how I'm encountering the problem at the moment.
I have 4 tables on a single page. When I show all the tables
at the same time, sure, the table tools buttons work for
each separate table, just like the example works.
However, once I put each table in its own separate "tab" div,
where the first tab is displayed when the page loads, and the
other three tabs are hidden until the tab links are clicked,
then the problems begin. The table in the first displayed
tab works: the table tools buttons can hover and can do print actions.
The tables in each of the hidden tabs, once they become the active tabs,
do NOT work. The button hover and the button clicking actions do nothing.
Has anyone come across this problem and found a fix for this?
The one forum posting shows a user had to resort to ajax to call each table,
and that seems pretty kludgy to me.
This discussion has been closed.
Replies
a div that is initially hidden from display, because if I use Table Tools on only 1 table,
and the table is inside a hidden div, then Table Tools
does NOT work on the 1 table when the hidden div display property changes.
Exact same thing...
Gust
[code]
$(document).ready(function(){
var oTable = $('.datatable').dataTable(tableLayout);
});
[/code]
And then add the tabs in the window ready function.
[code]
$(window).ready(function(){
$(".tabs").tabs();
});
[/code]
I'm loading the tab content using ajax. Anyone are using ajax to retrieve the tab content too ?
I've found a message in firebug's console, pointing to ZeroClipboard.js line 133:
[code]
this.domElement.parentNode.appendChild(this.div);
[/code]
Error message:
[code]this.domElement.parentNode is null[/code]
When trying to safe call appendChild() method, the buttons doesn't work as expected.
[code]
if (this.domElement.parentNode != null) {
this.domElement.parentNode.appendChild(this.div);
}
[/code]
[code]
if(ZeroClipboard){
var ZeroClipboard; // If exists clear previous clipboard
}
[/code]
Doesn't worked for me. Same error.
[code]
if ( document.getElementById(id) && (node.parentNode) )
[/code]
I do get rid of the error, however I also cause the CSV and Excel buttons do not always function. The Copy button seems to always work though. (I am not using the PDF/Print buttons)
I am using fnDestroy() then creating a new table and using DataTables again without refreshing the page. Has anyone had any luck fixing this issue?
One additional note is that this is not a problem if I do not attempt to use the save functionality of TableTools. The problem only occurs after I have saved something.
How I am removing Data Tables:
[code]oTable = $('#example').dataTable();
oTable.fnDestroy();
$("#example").remove();[/code]
What was happening was that there were divs being inserted into the table with class "DTTT_collection" **and** into the body of the page outside of the table (for the collections popup). My code above was destroying the table, but not these extra popup collections. So, I added:
[code]$('.DTTT_collection').remove();[/code]
After the code above, and now it works. I have no idea why.
I have 11 tabs in one page. Every one includes a jquery data table the csv exporting works fine in the first tab only
I tried this solution and it works fine :)
[code]
$j( "#tabs" ).tabs({
"select": function(event, ui) {
var dTable = $j('.data-table', ui.panel).dataTable();
if ( dTable.length > 0 ) {
iniDataTable(dTable);
}
}
});
[/code]
iniDataTable() function
[code]
/**
* iniDataTable
*/
function iniDataTable(dTable){
//destroy first
dTable.fnDestroy();
//reinitialize datatable
dTable.dataTable({
"iDisplayLength": 20,
"bJQueryUI": true,
"bSort": false,
"bJQueryUI": true,
"sDom": '<"H"Tfr>t<"F"ip>',
"oTableTools": {
"sRowSelect": "single",
"sSwfPath": "../js/copy_cvs_xls_pdf.swf",
"aButtons": [
{
"sExtends": "csv",
"sCharSet": "utf8",
"sFieldBoundary": '"',
"bBomInc": true,
"sButtonText": "CSV"
},
{
"sExtends": "print",
"sInfo": "Please press escape when done",
"sButtonText": "Print",
"bSelectedOnly": true
}
]
}
}).css("width","100%");
}
[/code]
For example,
[code]
{
"sExtends": "collection",
"sButtonText": "Save",
"aButtons": [ "csv", "xls", "pdf" ]
}
[/code]
$('.DTTT_collection').remove();
Same type of senario, destroy and recreate multiple tables on same page, on 2nd+ create - TableTools fails on Mozilla (fine in IE supprisingly). Couldnt find the DT destory function doesnt cascade down to its plugins extensions.
[code]
getDOMObjectPosition: function(obj) {
var info = Object();
// get absolute coordinates for dom element
if ($(obj).is(":visible")){ //obj.widht and obj.offsetWidth only work on visible elements
info = {
left: 0,
top: 0,
width: obj.width ? obj.width : obj.offsetWidth,
height: obj.height ? obj.height : obj.offsetHeight
};
} else {
//clone the object into a div outside of the window
var tempDiv = $('');
var objClone = $(obj).clone();
objClone.appendTo(tempDiv).appendTo($('body'));
//get the info needed
info = {
left: 0,
top: 0,
width: objClone.width ? objClone.width : objClone.offsetWidth,
height: objClone.height ? objClone.height : objClone.offsetHeight
};
//destroy the temporary objects
objClone.remove();
tempDiv.remove();
}
if ( obj.style.width != "" )
info.width = obj.style.width.replace("px","");
if ( obj.style.height != "" )
info.height = obj.style.height.replace("px","");
while (obj) {
info.left += obj.offsetLeft;
info.top += obj.offsetTop;
obj = obj.offsetParent;
}
return info;
}
[/code]
this works for me perhaps it's useful for you too.
I had to make a small change to get this working with TableTools v2.1.2
[code]
getDOMObjectPosition: function(obj) {
var info = Object();
// get absolute coordinates for dom element
if ($(obj).is(":visible")){ //obj.widht and obj.offsetWidth only work on visible elements
info = {
left: 0,
top: 0,
width: obj.width ? obj.width : obj.offsetWidth,
height: obj.height ? obj.height : obj.offsetHeight
};
} else {
//clone the object into a div outside of the window
// -------------- CHANGE HERE -----------------
var tempDiv = $('');
// -------------- END CHANGE ------------------
var objClone = $(obj).clone();
objClone.appendTo(tempDiv).appendTo($('body'));
//get the info needed
info = {
left: 0,
top: 0,
// -------------- CHANGE HERE -----------------
width: objClone.width() ? objClone.width() : objClone.offsetWidth(),
height: objClone.height() ? objClone.height() : objClone.offsetHeight()
// -------------- END CHANGE ------------------
};
//destroy the temporary objects
objClone.remove();
tempDiv.remove();
}
if ( obj.style.width != "" )
info.width = obj.style.width.replace("px","");
if ( obj.style.height != "" )
info.height = obj.style.height.replace("px","");
while (obj) {
info.left += obj.offsetLeft;
info.top += obj.offsetTop;
obj = obj.offsetParent;
}
return info;
}
[/code]