how to make fnGetPosition work?

how to make fnGetPosition work?

pojkepojke Posts: 2Questions: 0Answers: 0
edited April 2012 in General
Hi,

I kind of understand how datatables index DOM seperately from the real DOM, but I can't make fnGetPosition work.
My code is really simple. I have a table, I'm creating datatables on this table and then doing really simple test:

[code]
$('.invisible[rel="en_'+rel+'"]').parent().html('clicked');
console.log( oTable.fnGetPosition( $('.invisible[rel="en_'+rel+'"]').parent() ) );
[/code]

So the first line works perfectly, but the second returns always Error: nNode.nodeName is undefined.
Tried probably dozen of possibilities, changing class to ID, got rid of rel... still nothing. Even tried (found somewhere on forum):
[code]
console.log( oTable.fnGetPosition( oTable.$('.invisible[rel="en_'+rel+'"]').parent() ) );
[/code]

But still nothing... Any suggestions?

Replies

  • pojkepojke Posts: 2Questions: 0Answers: 0
    Ok figured it out. There is nothing mentioned in documentation which is pretty bad as I lost couple of hours to find out that to get position you can't pass jQuery object but DOM element...
    So to above code what you have to do is to add jQuery .get(0) method to the parent object and then pass it to fnGetPosition:
    [code]
    oTable.fnGetPosition( $('.invisible[rel="en_'+rel+'"]').parent().get(0);
    [/code]
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Hi,

    Good to hear you found a solution to this problem. The documentation does note that a node is expected, which is generally true for most DataTables API methods where it deals with elements, rather than jQuery objects: http://datatables.net/ref#fnGetPosition . However, this is certainly a limitation in DataTables and I will be looking at relaxing that constraint and allowing jQuery objects to be passed in - possibly v1.10 or v1.11.

    Regards,
    Allan
This discussion has been closed.