apache-flexfilterfunction

removing an item from a filtered ArrayCollection


I'm having some issues when calling getItemIndex on an ArrayCollection with a filterFunction set.

I do something like myAC.removeItemAt(myAC.getItemIndex(myObject)), which works fine when the filtering hasn't been applied. As soon as filtering is applied, getItemIndex seems to return -1 in every case.

Has anyone come across this before? What the best way to remove an item form a filtered ArrayCollection?

Thanks a lot.

Evan


Solution

  • What exactly is your filter filtering out? If you've filtered out everything, getItemIndex should return -1.

    Are you hoping to remove items that are still visible when your filter has been applied? If you still want to remove an item that's filtered out, you could temporarily disable the filter:

    var filter:Function = ac.filterFunction;
    ac.fiterFunction = null;
    ac.refresh();
    
    // remove item
    
    ac.filterFunction = filter;
    ac.refresh();