Vertical Scrolling containing Inner table with thead tag gives JS Error
Vertical Scrolling containing Inner table with thead tag gives JS Error
jasheets1
Posts: 10Questions: 0Answers: 0
My table has a nested inner table within a td cell in the parent. Both parent and child tables have a thead element. When applying dataTables with a sScrollY to do vertical scrolling I get a JS Error: Node was not found Line 3064.
Removing the thead from the inner table eliminates the JS Error. I am using the latest released 1.9.0 version.
Line 3061 appears to grab any thead within the table, then remove it in line 3064.
[code]
var nTheadSize = o.nTable.getElementsByTagName('thead');
if ( nTheadSize.length > 0 )
{
o.nTable.removeChild( nTheadSize[0] );
}
[/code]
I believe this can be fixed by only grabbing thead elements that are direct children of the table on line 3061, like this:
[code]
var nTheadSize = $(o.nTable).children('thead'); //was var nTheadSize = o.nTable.getElementsByTagName('thead');
if ( nTheadSize.length > 0 )
{
o.nTable.removeChild( nTheadSize[0] );
}
[/code]
The fix appears to work for me, but I have only lightly tested it for my specific needs.
Here is my sample table:
[code]
Col 1Col 2
Data 11Data 12
In 1In 2
id 1id 2
id 3id 4
next
Data 31Data 32
$("#resultsDisplay").dataTable({"sScrollY": "100px"});
[/code]
Removing the thead from the inner table eliminates the JS Error. I am using the latest released 1.9.0 version.
Line 3061 appears to grab any thead within the table, then remove it in line 3064.
[code]
var nTheadSize = o.nTable.getElementsByTagName('thead');
if ( nTheadSize.length > 0 )
{
o.nTable.removeChild( nTheadSize[0] );
}
[/code]
I believe this can be fixed by only grabbing thead elements that are direct children of the table on line 3061, like this:
[code]
var nTheadSize = $(o.nTable).children('thead'); //was var nTheadSize = o.nTable.getElementsByTagName('thead');
if ( nTheadSize.length > 0 )
{
o.nTable.removeChild( nTheadSize[0] );
}
[/code]
The fix appears to work for me, but I have only lightly tested it for my specific needs.
Here is my sample table:
[code]
Col 1Col 2
Data 11Data 12
In 1In 2
id 1id 2
id 3id 4
next
Data 31Data 32
$("#resultsDisplay").dataTable({"sScrollY": "100px"});
[/code]
This discussion has been closed.
Replies
[code]
$(o.nTable).children('thead, tfoot').remove();
[/code]
I've just put that in and committed it. It is now available in the 1.9.1.dev nightly ( http://datatables.net/download ) and it will be in 1.9.1.
Thanks for flagging this up and the test case :-)
Regards,
Allan
Also, as a side note, I found an unrelated issue and commented on it here:
http://datatables.net/forums/discussion/comment/30522#Comment_30522
Thanks,
-- Jeff
On IE9 sorting is now broken. The first column you click to sort will work fine, but clicking additional columns does not sort those columns
Also, in IE9 I have this issue:
http://datatables.net/forums/discussion/8436/1.9.0-ie9-bug-console-is-undefined#Item_1
Allan
Click the compatibility mode button in IE9 and you'll see the example will no longer sort.
I don't have IE8 available, but I wonder if this means it is broken in IE8 too...