FYI: Deleting rows on filtered data.

FYI: Deleting rows on filtered data.

fecundfecund Posts: 15Questions: 0Answers: 0
edited November 2011 in General
I use an ajax call outside of DT to delete rows from my table. Everything worked out until I tried to delete a row that was hidden by filtering. I had tried this:

[code]oTable.fnGetPosition(document.getElementById(id));[/code]
and this:
[code]oTable.fnGetPosition($("#" + id)[0]);[/code]

Until I saw allan mention this method:
[code]oTable.fnGetPosition($(oTable.fnGetNodes()).filter('#'+id)[0]);[/code]

That worked all the time and for all variations(filtered, hidden, etc..) and the output is passed to oTable.fnDeleteRow of course.

I did find that if you pass null (i.e. the selector doesn't match, or element not found) it causes fnGetPosition to die (at least in chrome). So I check for that before calling it. I just didn't include that for brevity. Just thought this might help some folks. If there is better/fast/efficient way please let me know.

Replies

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Good tip - fnGetNodes is key to working with TR elements in DataTables. At some point I want to add a selector like option to make this kind of thing much easier... :-)

    Allan
This discussion has been closed.