Cannot read property 'nodeName' of null, ONLY the first time I try to sort a table

Cannot read property 'nodeName' of null, ONLY the first time I try to sort a table

deckoffdeckoff Posts: 11Questions: 0Answers: 0
edited December 2013 in General
This is a weird issue, which results in
[code] Cannot read property 'nodeName' of null [/code] in [code] jquery.dataTables.min.js:105 [/code]
The error pops out only once, the first time I try to sort a table column. The table with not sort, but I will get the above error. Once the error appears, sorting works, and I dont get the error anymore. I suppose the first instance of sorting happens before nodeName being defined???
The page is deployed on my local laptop, so I cannot link to the whole page.
Here are links to the javascript that defines the table, and the html code, that goes with it:
http://pastebin.com/09Rf6gVF
http://pastebin.com/BnuaxEGn

Here is the live preview, but it works ok :(
http://live.datatables.net/ipusag/5/edit

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    If you try it with the unminified file, what is the line number of the error? Might help us narrow it down a little, although its really a test case showing it broken which would help :-)

    Allan
  • deckoffdeckoff Posts: 11Questions: 0Answers: 0
    Does anyone knows a good place where I can upload the whole page (it contains a good amount of js plugins plus a complete framework) for free, let it stay for a month or so(until bug fixed), and delete it
  • deckoffdeckoff Posts: 11Questions: 0Answers: 0
    http://testbet.hostingsiteforfree.com/

    I managed to upload the code, with a test database. I also switched to non mini version of datatables. Now the error is fired EVERY time, not only the first .
    The error is in line
    [code]jquery.dataTables.js:5698 [/code]
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    That's for the link to the test case - I would never have found the issue without it!

    > var bet = formatTable.fnGetData($('body').data("chosenTR"));

    You are passing in a jQuery object, but fnGetData expects a node. Use:

    [code]
    var bet = formatTable.fnGetData($('body').data("chosenTR")[0]);
    [/code]

    DataTables 1.10's new API will be able to cope with jQuery objects being passed in :-)

    Allan
  • deckoffdeckoff Posts: 11Questions: 0Answers: 0
    Things are pretty damn obvious, once one solves a given problem, not only in that case. ;)
    [code]
    $('body').on('click', "tr", function() {
    ....
    "chosenTR": formatTable.fnGetPosition($(this).closest('tr')[0])
    ...
    var bet = formatTable.fnGetData($('body').data("chosenTR"));
    [/code]
    I try to get all values located in a row, addressing the first cell. Since the function triggers on every tr clicked, it will trigger on thead when I want to sort, too, but the value will be null, so the error.
    Case closed
This discussion has been closed.