0

Use Case:

  1. End-User searches for something and an ArrayCollection is returned with Result objects. This is displayed in a data grid.
  2. End-User selects a few of the search results and "moves" it over to another datagrid for use later.
  3. End-User does another search.

PROBLEM: Some of the search results might contain something the user already previously selected and moved over to the second datagrid. I want to remove these from the second search result.

How can I do this quickly, and efficiently in Flex code?

LazerWonder
  • 118
  • 1
  • 9

2 Answers2

1

disableAutoUpdate() on both array collection

loop through the first one and for each item of the second remove it if it's present in the first one (or adapt the algorithm based on what you really want - unsure)

enableAutoUpdate() at the end.

Looping through array collection can be quick if no events are dispatched.

Second option, you could also loop through a cheap copy made up of an array, which is arraycollection.source.concat(), or even a vector if all your items are of the same type. That will give the maximum speed, but you might lose in the long run as you need to convert back to an array collection at the end.

So I would stick to the first option.

keyle
  • 2,762
  • 3
  • 24
  • 27
  • I am certain these methods will work as I've thought of them too. I guess I was trying to avoid nested for-loops as these arrays can get pretty big.... – LazerWonder Feb 10 '12 at 15:22
  • unless they're millions of records - you should be ok. – keyle Feb 12 '12 at 22:25
0

For the time being, I've implemented a hash collection (extends ArrayCollection). Hash only allows unique values, so in the end, it serves my purpose even though the UI might be confusing to the user. Will probably implement the above method at a later date. :)

LazerWonder
  • 118
  • 1
  • 9