RKCY
RKCY

Reputation: 4135

ArrayCollection index got changed after filter the arraycollection

I have a advanced datagrid and populating some data by using arraycollection. And i am filtering the arraycollection, the arraycollection index got changed.

Arraycollection:- [0] - name: abc
                  [1] - name: hello
                  [2] - name: hello1
                  [3] - name:hai

after filtering the arraycollection as 'hell' , the array collection is displaying like the below:

Arraycollection:- 
                  [0] - name: hello1
                  [1] - name: hello

Can i know the reason why the index got changed after filter it?

* no server side code for filtering. it is only flex side filtering.

Upvotes: 1

Views: 501

Answers (2)

The_asMan
The_asMan

Reputation: 6402

ArrayCollection has a few very nice and unique properties.
One property is that it can be bound.
This binding property allows you to set the collection as a dataprovider for a flex object like a TileList.
So when the collection is filtered the TileList will repopulate automatically using the filtered data with no additional code.

Another property is source. This is the unfiltered/unchanged data.

When a filter has been applied to the collection the new data will be the source minus the elements that failed the filter test.
As you can see your filter only passed 2 items and returned the new collection of 2 elements.
You can NOT assume the index values of any given element will not change Also use arrCol.refresh( ); after you apply a filter for databinding to work.

Upvotes: 0

aioobe
aioobe

Reputation: 420971

The ArrayCollection not an associative array or a map, it's a wrapper for an ordinary array indexed by integers.

I.e., you can't have an array which only contains an element at index 1 and 2.

From the documentation of filter:

Executes a test function on each item in the array and constructs a new array for all items that return true for the specified function. If an item returns false, it is not included in the new array.

Upvotes: 2

Related Questions