Vertical Scrolling containing Inner table with thead tag gives JS Error

Vertical Scrolling containing Inner table with thead tag gives JS Error

jasheets1jasheets1 Posts: 10Questions: 0Answers: 0
edited February 2012 in Bug reports
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]

Replies

  • allanallan Posts: 63,383Questions: 1Answers: 10,449 Site admin
    Good catch, thanks for letting me know about that! The chunk of code can actually be significantly simplified to just:

    [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
  • jasheets1jasheets1 Posts: 10Questions: 0Answers: 0
    Thanks for the quick response! The 1.9.1.dev build is working great for me now.

    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
  • jasheets1jasheets1 Posts: 10Questions: 0Answers: 0
    edited February 2012
    Sorry, actually 1.9.1.dev works great for me on Firefox 10.0, but there is a bug in IE9.

    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
  • allanallan Posts: 63,383Questions: 1Answers: 10,449 Site admin
    I've just put your example into a live demo: http://live.datatables.net/ehupac . It seems to work okay with 1.9.1.dev in IE9 for me.

    Allan
  • jasheets1jasheets1 Posts: 10Questions: 0Answers: 0
    Hmmm, weird. It breaks when IE9 is set in compatability mode. But it works in straight IE9 mode.

    Click the compatibility mode button in IE9 and you'll see the example will no longer sort.
  • jasheets1jasheets1 Posts: 10Questions: 0Answers: 0
    Any luck on fixing in IE9 compatability mode?

    I don't have IE8 available, but I wonder if this means it is broken in IE8 too...
This discussion has been closed.