fnGetPosition on a causes an error

fnGetPosition on a causes an error

dondochakadondochaka Posts: 3Questions: 0Answers: 0
edited March 2012 in General
I'm getting

[code]Uncaught TypeError: Cannot read property 'nTr' of undefined[/code]

when I try to do

[code]
$(table).find(".myClass").each(function (index, value) {
var dtIndex = table.fnGetPosition( this );
...
[/code]

table is the result of a .dataTable call on a dom element saved in a variable and fully initialized. The results of the .find() are some elements that have been initialized with bVisible as false.

Any ideas?

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Can you link me to a demo show showing this issue please? If a column has been hidden using bVisible, then its cells shouldn't be getting selected by the query you have above, although I think I can see how trying to find a cached, hidden cell in fnGetPosition would be an issue.

    Allan
  • dondochakadondochaka Posts: 3Questions: 0Answers: 0
    This should get at what I'm trying to do: http://jsfiddle.net/tnunamak/QPbuF/

    The error occurs when the toggle function is called. I realized that if I set bVisible to false it actually prevents the .find() from matching the columns, so I tried it another way (toggle2()) hoping that it would find the TH's according to the documentation here http://datatables.net/api. Turns out that it doesn't just not find just the TH's with bVisible set to false, it doesn't find any of them. Am I using it wrong?
  • dondochakadondochaka Posts: 3Questions: 0Answers: 0
    Bumping this question
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Thanks for the JSFiddle link - its not fnGetPosition being used on the TH that is the problem, it is fnGetPosition being used on an element outside the TBODY. fnGetPosition is used to get the internal data position of the data in the table's cache - it shouldn't really be used now (it useful to be useful before about 1.6, but it is best avoided now).

    From your code - you want to get the column index of the column, based on its current position - is that correct? For that, use this plug-in: http://datatables.net/plug-ins/api#fnVisibleToColumnIndex

    Allan
This discussion has been closed.