Possibly a bug with oTable.$() method

Possibly a bug with oTable.$() method

MathObsessedMathObsessed Posts: 7Questions: 0Answers: 0
edited July 2012 in Bug reports
Hello again, Allan!

I feel sorry to bother you again but it seems that I've hound a bug in your plugin. The deal is:

1) I create a DataTable instance with server-side processing.
2) I'm trying to use your new cool feature - oTable.$("selector") function inside a "fnInitComplete" function
3) I recieve a JavaScript error like "a is null" and it seems to be a jQuery function error not DataTables plugin function...

So I assume the plugin is trying to call something like $("selector", container) of a standart jQuery but there is no "container" variable because I use async request... Can you help me with this problem please? Or if I missed something can you show me a topic in documentation that describes this kind of behavior?

My initial problem is - I need to check some previously checked checkboxes inside of my table, and this table appears in a modal window with the help of an AJAX request. All was fine with previous DataTable versions, but you kinda changed the behavior of your oTable.fnGetNodes() function since then... In prev versions this function returns ALL nodes (on all pages including insivsible nodes), nowadays it returns only visible nodes! I really think that now this function does what it HAS to be done, but your new $() function doesn't seem to work as one could expect! And moreover - there seems to be no sign of handling an error or at least a documented case for this!

~Ernest Lebedev

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    There are two possibilities off the top of my head:

    1. You aren't using Ajax loading and thus oTable has not yet completed its initialisation and you should use this.$(...) rather than oTable.$(...)

    2. You are using DataTables 1.9.0 or 1.9.1 and deferred rendering, where rows which have not yet been created are null and are passed on to jQuery which objects.

    Is it one of these two? If not, can you please run your table through the debugger so I can assist without too much guess work :-)

    Allan
  • MathObsessedMathObsessed Posts: 7Questions: 0Answers: 0
    edited July 2012
    You were right, Allan... I used v1.9.1 and kinda afraid to switch to 1.9.2 because of possible behavior changed :). Anyways in 1.9.2 the oTable.$() works just fine but it ALSO returns only first 50 rows for me!

    And as I said I need ALL rows because I have like 2000-8000 rows in my tables and 50 is just have no use for me... And workarounds like, you know, switching off pagination or switch to option "all" in pagination select wont work because they take vast amounts of time to only render 8000 rows in browser!

    For now I'm trying to use some REALLY ugly workarounds like:

    $.each(oTable._fnGetDataMaster(), function(index, rowElement){
    var firstCell = ""+rowElement[0]+"",
    cellCheckboxName = $(firstCell).find(":checkbox").attr("name"),
    tempVar;

    if ($.inArray(cellCheckboxName, curSelected) !== -1) {
    tempVar = $(""+oTable.DataTable.settings[1].aoData[index]._aData[0]+"");
    tempVar.find(":checkbox").attr("checked", "checked");
    oTable.DataTable.settings[1].aoData[index]._aData[0] = tempVar.html();
    }
    });

    But it is also slow of course as you can see... I use lines of code like this: ""+rowElement[0]+"" so I can use jQuery selectors after instead of regular expressions and shouldn't be bothered with any HTML changes in the future...

    ~Ernest Lebedev
  • MathObsessedMathObsessed Posts: 7Questions: 0Answers: 0
    Oh, and by the way while this oTable.$() function is now working for me I searched for its arguments and tried to apply this:

    @param {string} [oOpts.page=all] Limit the selection to the currently displayed page
    * ("current") or not ("all"). If 'current' is given, then order is assumed to be
    * 'current' and filter is 'applied', regardless of what they might be given as.

    But with no results :(
    I tried:

    console.log(oTable.$(":checkbox").length); //returns 50
    console.log(oTable.$(":checkbox", {"page": "all"}).length); //returns 50
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    > Anyways in 1.9.2 the oTable.$() works just fine but it ALSO returns only first 50 rows for me!

    You are using deferred rendering. The whole point of deferred rendering is that the TR nodes don't get created on first draw. If you want to access them, you need to allow them to be created by removing deferred rendering.

    Allan
  • MathObsessedMathObsessed Posts: 7Questions: 0Answers: 0
    Thank you very very much Allan!
    This finally returned me all 3500 rows that needed :)
This discussion has been closed.