DataTables logo DataTables

via Ad Packs
Problem with fnGetPosition following fnAddTr
  • sronsieksronsiek
    Posts: 19
    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.

     var new_row = $('<tr id="123"><td><a id="123_name">Fred</a></td><td>Flintstone</td></tr>')
     new_row.children('td').first().addClass('center') // Correct buglet in fnAddTr
    
     oTable.fnAddTr(new_row[0])
     var idx = oTable.fnGetPosition( new_row[0] )
    

    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
  • allanallan
    Posts: 15,883
    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: 19
    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: 19
    Ok - now I really got it! There is an updated version of fnAddTr which sets _DT_RowIndex:

    nTr._DT_RowIndex = iIndex;
    

    I had updated DataTables but not the plugin!
  • allanallan
    Posts: 15,883
    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: 19
    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.
← All Discussions

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Support

Get useful and friendly help straight from the source.

In this Discussion