Problem with fnGetPosition following fnAddTr

Problem with fnGetPosition following fnAddTr

sronsieksronsiek Posts: 52Questions: 11Answers: 0
edited June 2012 in Plug-ins
Hi,

I'm using fnAddTr in a table to add a row. The row is inserted as expected.
No second argument, so the plugin calls the internal _fnReDraw function.

When I now call fnGetPosition with the same row element, it returns null instead
of the row index. The index is needed for row deletion.

[code]
var new_row = $('FredFlintstone')
new_row.children('td').first().addClass('center') // Correct buglet in fnAddTr

oTable.fnAddTr(new_row[0])
var idx = oTable.fnGetPosition( new_row[0] )
[/code]

At this point idx is null.

Additional info:

oTable.fnGetNodes() and oTable.fnGetData() both return array *including* the added row!

DataTable v1.9.1

Any ideas for a workaround (other than fnAddData) ?

thanks,
Stefan

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    I would say never use fnGetPosition - it is a legacy API method, If you are deleting the row with fnDeleteRow just pass the node in.

    Having said that, it should work, and I'm not sure why it isn't. An example would be really useful.

    Allan
  • sronsieksronsiek Posts: 52Questions: 11Answers: 0
    This may be the answer:

    _fnNodeToDataIndex changed: in 1.8.2 is was traversing aoData (worked), in 1.9.1 it's looking at _DT_RowIndex on the node element, which is set in _fnCreateTr. Now fnAddTr calls _fnAddData, which I think does not set _DT_RowIndex ...
  • sronsieksronsiek Posts: 52Questions: 11Answers: 0
    Ok - now I really got it! There is an updated version of fnAddTr which sets _DT_RowIndex:

    [code]
    nTr._DT_RowIndex = iIndex;
    [/code]

    I had updated DataTables but not the plugin!
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Ah yes - fair enough. Good to hear you got it working.

    I do have longer term plans to make the plug-ins more version compatible - particularly now that they are in git :-)

    Allan
  • sronsieksronsiek Posts: 52Questions: 11Answers: 0
    I did not find any links to git here - I've been ut-pasting plugin code from http://datatables.net/plug-ins/api !
    Maybe add some links?
This discussion has been closed.