Using bVisible reports error nTh.parentNode is null

Using bVisible reports error nTh.parentNode is null

ianhaycoxianhaycox Posts: 2Questions: 0Answers: 0
edited July 2010 in General
Hi,

I'm using DataTables V1.6.2 with server-side processing and trying to hide a column but get the error:

Firefox 3.5.9: Error: nTh.parentNode is null Source File: http://blah/js/jquery.dataTables.min.js Line: 240
Chrome 5.0.?: Uncaught TypeError: Cannot call method 'removeChild' of null Line 240

Also tried the beta but the same error. I'm not a expert in JS/jQuery so it may be a user mistake.

Below is my js code:

[code]
jQuery(document).ready(function($) {
$("#test").dataTable({
"bProcessing": true,
"bServerSide": true,
"bFilter": false,
"iDisplayLength": 12,
"bLengthChange": false,
"bAutoWidth" : false,
"aoColumns": [
{ "sClass": "rank", "sWidth": "24%" },
{ "sClass": "user", "sWidth": "50%" },
{ "sClass": "points", "sWidth": "24%" },
{ "bVisible": false }
],
"oLanguage": {
"sInfo": "Showing _START_ to _END_ of _TOTAL_ entries"
},"fnRowCallback": function (nRow, aData, iDisplayIndex) {
if (aData[3] == 1) {
nRow.className = "logged-in-user";
}
return nRow;
},
"sAjaxSource": test.php
});
});
[/code]

Changing bVisible to { "sClass": "hidden", "sWidth": "1%" } works as a temporary fix, but the hidden column are user Id's which I would prefer to not show in the page.

Apart from this minor glitch everything works brilliantly and I'm really impressed. Thanks.

If you need any more info, let me know.

Regards,

Ian.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi Ian,

    What does your HTML in the thead element look like? I'm going to guess that there aren't 4 TH elements in the THEAD>TR as that would cause this error. Is that the case? If not, could you perhaps post your HTML please?

    Thanks!
    Allan
  • ianhaycoxianhaycox Posts: 2Questions: 0Answers: 0
    Hi,

    Thanks for the swift response.

    Yes, there are only 3 elements.

    Just added a dummy and it works with bVisible and the dummy TH is not rendered.

    I assume adding the dummy header column is the correct way.

    Thanks.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Yes this is the way to do. DataTables expects to find exactly the same number of columns as specified in the aoColumns initialisation array. The reason for this is that DataTables works from the principle of progressive enhancement - it assumes that the table is "fully" present before initialisation and will manipulate the dom as required. In this case it will remove the th (and related td's) from the dom (caching them in case you want to put them back later).

    Regards,
    Allan
This discussion has been closed.