BUG: table.row(...).node(...).to$ is not a function

BUG: table.row(...).node(...).to$ is not a function

mooseburgermooseburger Posts: 6Questions: 3Answers: 0

The singular function row().node():

http://datatables.net/reference/api/row%28%29.node%28%29

Does not return an API object, so you can't call to$() on it. Instead, one must call row().nodes().to$() (note the plural on node).

Example:

http://live.datatables.net/heziruvo/1/edit

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,441Questions: 1Answers: 10,459 Site admin

    I'm afraid I don't see why this is a bug. The documentation (which you linked to) notes that the row().node() method returns a node and not a DataTables API instance. This is intended and expected (although I realise that it might have been more convenient to always return a jQuery object...).

    You could also use $( table.row( ... ).node() ).

    Allan

  • mooseburgermooseburger Posts: 6Questions: 3Answers: 0

    While that is true, it is a bit misleading that I have to use nodes() for the singular case. The other row functions don't work like that. Doesn't row().node() to get a single API instance make more sense than row().nodes()? Especially considering there is a rows().nodes().

  • allanallan Posts: 63,441Questions: 1Answers: 10,459 Site admin
    Answer ✓

    rows().nodes() must return a collection - be it an array or an array like object. It could (possibly should) return a jQuery object, but it returns an API instance like all other API methods that return a collection.

    row().node() however does not need to return a collection - it gives access to a single entity only. So like the other DataTables API methods that return a single value it does not return an API instance. Consider for example column().visible() - it returns a boolean.

    The difference between the singular and plural is a key item in the DataTables API - it is important to understand the difference between them.

    Allan

  • mooseburgermooseburger Posts: 6Questions: 3Answers: 0

    The documentation I linked to has as an example:

    table
        .row( '#row-4' )
        .node()
        .to$()      // Convert to a jQuery object
        .addClass( 'ready' );
    

    This code does not work as of 1.10.7, since, as you noted, node() returns a node object, not a DataTables API instance. Specifically, one gets Type Error '.to$ is not a function'.

    Maybe the example for row().node() needs to be changed.

  • allanallan Posts: 63,441Questions: 1Answers: 10,459 Site admin
    Answer ✓

    Hi,

    Thanks for pointing that out! rows().node().to$() will work, but using a singular row() will not work. I'll correct the example and deploy it to the site shortly!

    Regards,
    Allan

This discussion has been closed.