Getting an error when using fnGetPosition

Getting an error when using fnGetPosition

arvinsimarvinsim Posts: 20Questions: 1Answers: 0
edited February 2012 in General
[code]
var val = $(event.target).find("option:selected").val(),
nColumn = $(event.target).closest("td").get(0);

var aPos = oTheaterTelephonesTable.fnGetPosition(nColumn);
[/code]

Somehow I get an error.

[code]
j is undefined
....nodeName.toLowerCase();if(d=="td"||d=="th")b.push(j.nTr.childNodes[e])}e=d=0;fo...
[/code]

I have tried some variants for the nColumn line

[code]
nColumn = $(event.target).closest("td").get();
nColumn = $(event.target).closest("td")[0];
[/code]

But I still get the error. I have searched for answers but the usual problem is that it is returning the wrapper instead of the actual DOM element. As you can see above, I have already returned the actual DOM element but it is still not working.z

Any ideas why I am getting that error?

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    This error typically means that the element you have given to fnGetPosition is not a row or cell that is under control of the DataTable (possibly because it has been injected using jQuery or DOM methods rather than using the DataTables API).

    Perhaps you can give us a link to the page? It might also be an idea to use the non-minified version of DataTables to see where the exact error is.

    Allan
  • arvinsimarvinsim Posts: 20Questions: 1Answers: 0
    [quote]This error typically means that the element you have given to fnGetPosition is not a row or cell that is under control of the DataTable (possibly because it has been injected using jQuery or DOM methods rather than using the DataTables API).[/quote]

    I am not sure but you may be right. The element that I passed is a select element in the footer to filter out its respective column(just like the examples here in the site on column filtering).
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Ah I see - so the TR element you are giving it is in the TFOOT rather than TBODY? That certainly would cause this error since fnGetPosition will only work on rows in the TBODY.

    What is it that you are trying to do?

    Allan
  • arvinsimarvinsim Posts: 20Questions: 1Answers: 0
    edited February 2012
    [quote]
    Ah I see - so the TR element you are giving it is in the TFOOT rather than TBODY? That certainly would cause this error since fnGetPosition will only work on rows in the TBODY.

    What is it that you are trying to do?
    [/quote]

    I was trying to use fnGetPosition to get the column index of the input text element. I use this index to know which column to filter(since the input text element is used to filter the column it is on).

    Is there an alternative way to get the column index in TFOOT?
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Two ways:

    Use the jQuery index method ( http://api.jquery.com/index/ ) - something like $('#example tfoot th').index( myTh );

    Or a plug-in API method that would loop over the TH elements in the columns object and find a match:

    [code]
    $.fn.dataTableExt.oApi.fnGetFooterIndex = function ( oSettings, nCell )
    {
    for ( var i=0, iLen=oSettings.aoColumns.length ; i
This discussion has been closed.