.toJQuery() and .to$() is "not a function" for .node() in DT 2.0
.toJQuery() and .to$() is "not a function" for .node() in DT 2.0
Loren Maxwell
Posts: 406Questions: 99Answers: 10
in Bug reports
I think this is a bug and not intentional, but .to$()
and .toJQuery()
return "not a function"
when used with .node()
.
Might be an artifact of this from the Release Notes:
Plural methods were available on singular API invocations. For example row().nodes() was available, even although there was no definition for it - it was rows().nodes() leaking through.
This question has an accepted answers - jump to answer
Answers
I checked my own code. I use "nodes().to$()" 55 times. But I never use "node().to$". Do you think the singular "node" instead of "nodes" causes the issue?
"header().to$" also works by the way.
I'm pretty sure it's the singular case.
Here's my code (run code associated with closing child rows on all the open ones) that causes the error:
It causes this error:
I've changed it to this, which works:
Using
to$()
never worked withrow().node()
or any of the other singular API's using.node()
. Theto$()
andtoJquery()
APIs are Datatable APIs and will only work with objects that contain an instance of the Datatable API.row().node()
returns just thetr
element whererows().nodes()
returns thetr
elements along with the Datatables API.Use
$()
to return a jQuery object fromrow().node()
, for example:The note you referenced is saying that using something like
row().nodes()
was never supported nor in the docs. It mistakenly worked and now 2.0 is tightened up so those APIs calls are now invalid.Kevin
Thanks, Kevin -- you might be right, it's intentional and not a bug and I just happen to actually be taking advantage of a previous "bug" that's now been corrected with 2.0.
Our posts crossed so you might not have seen mine just a few minutes prior to yours, but I've gone to the
$()
you mentioned and it works as expected.Hmm, not sure how that worked. May have been a bug in the particular version you are using. I tried this code with 1.13.7 and it throws the same error:
https://live.datatables.net/migoniga/1/edit
Kevin
Hey Kevin!
I thought that $( ) and to$ were freely interchangeable. I was wrong. Learned something. Thanks.
Roland
@kthorngren -- I had been using 1.13.7.
Technically this was the code previously, although it shouldn't have made any difference:
When I upgraded to 2.0 I got the
"not a function"
error, and so I changed it to use$()
and then added the `.dt-hasChild' row selector:How interesting - I hadn't realised there was that loop hole! The
row().node()
method should return an HTML element, which don't have a.to$()
method, hence the error. The fact that it worked in 1.x was a bug!Allan