How timely! 

I just spoke about this at my MAX talk - the code example and supporting
slides are on my blog: http://iamdeepa.com/blog/?p=7 Look for the code
example and slides called "Merged Collections". 

Basically what you want to do is write a custom collection that does the
merging of your data for you. All the list-based controls can take
collections as dataProviders so your custom collection can be set as the
dataProvider of your list control, and boom, you're done.

My example shows a custom implementation of IList - which is the easier
of the collection interfaces and will probably suit your needs just
fine. (The other collection interface is ICollectionView). What you'll
want to do is make sure a getItem() on your merged collection does a
getItem() call on the sub collections and produces a merged object
representing the data you desire. You'll also need to implement the
getter for the length property on IList (which looks easy since I
believe you stated that the sub collections are the same length so you
can just return the length of one of those sub collections). My example
on my blog goes on to show how you can implement the add/remove/modify
logic so that changes in the underlying collection gets pushed up to the
merged collection and the UI control updates.

Note: I am missing something key in my example. You'll want to cache the
merged item created by the getItem() call in a dictionary or hash table
and return that upon subsequent getItem() calls (basically, getItem()
should see if a merged object already exists for that index and return
that, otherwise build up a new merged object). Also, implement IUID so
that the merged objects have a unique ID which is required by the list
controls.

HTH -
deepa

-----Original Message-----
From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Andrew
Sent: Wednesday, June 13, 2007 9:57 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: Joining two (or more) ArrayCollections

I actually tried following this approach:


public function combineArrayCollections ():void {

for each (var obj:Object in ac1) {
  ac3.addItem ( obj );
}
for each (obj in ac2) {
  ac3.addItem ( obj );
} 
}

Using the example of having 3 rows in each field the result I get 
isn't what I was hoping for.  

When I combine the two AC's in this way I get (eg. assuming 3 rows 
per field):

ac3 =
Field 1 / Field 2 / Field 3 / Field 4
object / object / null / null
object / object / null / null
object / object / null / null
null / null / object / object 
null / null / object / object 
null / null / object / object 

What I'm really looking for is:
Field 1 / Field 2 / Field 3 / Field 4
object / object / object / object 
object / object / object / object 
object / object / object / object

I hope this makes sense.  So I'm really close now, but I'm missing 
something key here.

--Drew

 




--- In flexcoders@yahoogroups.com, "Arpit Mathur" <[EMAIL PROTECTED]> 
wrote:
>
> ac2.source.push(ac1.source) should work.
> 
> -arpit
> ------------------------
> post your flex tips on
> http://flextips.corank.com
> 
> 
> On 6/12/07, Michael Schmalle <[EMAIL PROTECTED]> wrote:
> >
> >
> >
> >
> >
> >
> > One solution;
> >
> > var ac3:ArrayCollection;
> >
> > var list1:Array = ac1.toArray();
> > var list2:Array = ac2.toArray();
> > list1 = list1.concate(list2);
> >
> > ac3 = new ArrayCollection(list1);
> >
> > don't know if that is what you are talking about.
> >
> > Peace, Mike
> >
> > On 6/12/07, Alex Harui <[EMAIL PROTECTED]> wrote:
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > Some folks actually take to DG's put them next to each other, 
turn off the
> > scrollbar on the left one and listen to events to keep 
everything in sync.
> > >
> > >
> > >
> > > It is also possible to make a custom ArrayCollection that 
combines the two
> > child ACs
> > >
> > >
> > >
> > > ________________________________
> >
> > >
> > > From: flexcoders@yahoogroups.com [mailto: 
[EMAIL PROTECTED] On
> > Behalf Of Andrew Mikkelsen
> > > Sent: Tuesday, June 12, 2007 1:17 PM
> > > To: flexcoders@yahoogroups.com
> > > Subject: [flexcoders] Joining two (or more) ArrayCollections
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > I've been searching and searching on this, but I can't seem to 
find an
> > answer on how to do this. Surely, someone, somewhere must have 
found the
> > need to do something similar to what I'm trying to do. :-)
> > >
> > > I have two ArrayCollections (eg. ac1 (field_1, field_2) and 
ac2 (field_3,
> > field_4)). Both AC's are the same length. What I'd like to do is 
mash the
> > fields from the two AC's together to get ac3(field_1, field_2, 
field_3,
> > field_4).
> > >
> > > My real goal is that I need a workaround for not being able to 
put
> > information from two separate dataproviders into a datagrid.
> > >
> > > Any help / suggestions would be greatly appreciated.
> > >
> > > Thanks!
> > >
> > >
> > >
> > > --Drew
> > >
> > >
> > >
> > >
> >
> >
> >
> > --
> > Teoti Graphix
> > http://www.teotigraphix.com
> >
> > Blog - Flex2Components
> > http://www.flex2components.com
> >
> > You can find more by solving the problem then by 'asking the 
question'.
> >
>




--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links



Reply via email to