Unable to use fnDeleteRow when the row is not currently visible

Unable to use fnDeleteRow when the row is not currently visible

ConnieCConnieC Posts: 4Questions: 0Answers: 0
edited July 2012 in General
I have a reasonably complex application where users often use filters to view only
some of the rows, but a byproduct of some of their actions on those rows are to
add or delete other rows not visible in the current filter.

I can add the rows just fine, but cannot figure out how to delete rows that are not
currently visible. (I have read just about every discussion re fnDeleteRow , but
have not found what I should be doing .. ?)

There is a simple example to show this (using 1.9.2), and it also provides more background.
http://beachwatchers.net/example/dt1/

Thanks in advance for any advice you can give me.

Connie C

Replies

  • ConnieCConnieC Posts: 4Questions: 0Answers: 0
    I've think I've found a solution - if the row is not visible, I use fnGetNodes, and loop over
    all the nodes to find the one with the matching DT_RowId.

    Is there a more efficicient way to do this?

    Thanks
  • ConnieCConnieC Posts: 4Questions: 0Answers: 0
    When I tried this in my real application --
    - using fnGetNodes and looping over the array to find the matching DT_RowId,
    and then using fnGetPosition to get the index to pass to fnDeleteRow, it works sometimes.

    My array has 152 rows, but fnGetNodes is only returning 15 or so?
    Probably the first 10 shown, plus the initial filter that returned 5.
  • allanallan Posts: 63,541Questions: 1Answers: 10,476 Site admin
    > Is there a more efficicient way to do this?

    If you know the ID of the row you want to delete then yes:

    [code]
    table.fnDeleteRow( table.$('#myRow')[0] );
    [/code]

    fnGetPosition should be avoided if you want (just because it adds an extra layer of complexity that you shouldn't need).

    Allan
  • allanallan Posts: 63,541Questions: 1Answers: 10,476 Site admin
    > My array has 152 rows, but fnGetNodes is only returning 15 or so?

    Do you have deferred rendering enabled?
  • ConnieCConnieC Posts: 4Questions: 0Answers: 0
    Using table.fnDeleteRow( table.$('#myRow')[0] ) seems to do the trick,
    in both my example/dt1 and in my real application (where I do have
    deferred rendering enabled)

    I had been using [code]
    var el = document.getElementById('myRow');
    table.fnDeleteRow(el);
    [/code]

    Thank you for you help, and your fantastic data table functionality.
This discussion has been closed.