Error: table.fnSettings() is null

Error: table.fnSettings() is null

shaishai Posts: 7Questions: 0Answers: 0
edited July 2011 in General
Hi

the first time i click the menuentry to get to my datatable page i can select my datatable entries without any problem.
Whenever i click on the menuitem again or another menuitem which loads another table into the content i get this error whenever i click on a datatable entry Error: table.fnSettings() is null. When i reload the page however everything is fine again.

[code]
var table = $('#example').dataTable({
"bJQueryUI": true,
"sScrollY" : "200px",
"aaSorting" : [ [ 1, 'asc' ] ],
"sPaginationType": "full_numbers"
});

// SELECTION OF ROWS
$("tr", table).live("click", function (event) {
if ($(event.target.parentNode).hasClass('selectedDataTableRow')) {
$(event.target.parentNode).removeClass('selectedDataTableRow');
$("#editTutorButton").button("disable");
$("#deleteTutorButton").button("disable");
} else {
$(table.fnSettings().aoData).each(function () {
$(this.nTr).removeClass('selectedDataTableRow');
});
$(event.target.parentNode).addClass('selectedDataTableRow');
$("#editTutorButton").button("enable");
$("#deleteTutorButton").button("enable");
}
});
[/code]

What seems to be the problem here?
greez

Replies

  • shaishai Posts: 7Questions: 0Answers: 0
    seems that there is a problem with the live function and the temp variable table
  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin
    I suspect that you will want to change "$("tr", table)" to "$("#example tbody tr") since 'table' is a DataTables instance array, not a node array.

    Other than that - it looks good to me - so hopefully that will do it!

    Allan
  • shaishai Posts: 7Questions: 0Answers: 0
    edited July 2011
    thx for the reply. but this doesnt help either. Still the same with the difference, that ne rows are not even selectable anymore. With $("#example tbody").live("click", function (event) {
    It is selectable again but it still doesnt make the error message of the else go away. table.fnSettings() is still null..

    There is a solution like this:
    $("#example tbody").click(function(event) {
    $(table.fnSettings().aoData).each(function (){
    $(this.nTr).removeClass('selectedDataTableRow');
    });
    $(event.target.parentNode).addClass('selectedDataTableRow');
    $("#editTutorButton").button("enable");
    $("#deleteTutorButton").button("enable");
    });

    But i still dont understand why the other solution does not work..
  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin
    Hmmm - not sure. That does seem a bit odd. It might be worth considering using TableTools in future for your row selection as that has row selection abilities built in and and API to allow reading / manipulation of the selection.

    Allan
This discussion has been closed.