Removing rows based on a filter

Removing rows based on a filter

bicklebickle Posts: 8Questions: 0Answers: 0
edited April 2014 in DataTables 1.10
I'm having some difficulty with deleting rows based upon filter results. I've tried both looping through the filter results and using the new rows().remove(), with varying levels of success.

I have a demo here at http://live.datatables.net/lijoyay/13/ . There are two buttons at the top that run a function that attempts to remove all rows where Office='New York'. If I use the looping button, the wrong records are deleted (I'm using draw(false). If I try the rows().remove() method, it just fails outright. So I assume that I'm referring to the filtered data incorrectly, but when I view the array in Firebug, I just see the rowindex, which is what I thought I needed.

Thanks,

Replies

  • allanallan Posts: 57,265Questions: 1Answers: 9,123 Site admin
    You are absolutely right in your code, that should work. That it isn't is a bug in DataTables... The issue was that it was checking the selector specifically for an array, but the code was passing in an API instance (it is array like, but not actually an array), so this was failing.

    A workaround would be to use the `toArray()` method chained onto your `filter()` . However:

    I've committed a fix here: https://github.com/DataTables/DataTablesSrc/commit/d9f41623 and I'll sync up the nightly build once I've finished going through the forum posts this morning incase there is anything else duff that needs to be fixed!

    Thanks for flagging this up and the test case - hugely appreciated!

    Regards,
    Allan
  • bicklebickle Posts: 8Questions: 0Answers: 0
    Thanks Allan! I was sure that I was just referring to an object incorrectly. I just loaded the new build and the rows().remove() method works great.
This discussion has been closed.