Flex Spark DataGrid selectedItems Vector

Posted: November 7, 2011 in ColdFusion, Flex

In Flex 1,2,3 we used mx:DataGrid, which had a dg.selectedItems Object.
In Flex 4,4.5,4.6+ we now use a Spark s:DataGrid, which made dealing with selectedItems more complicated with Vectors. Jury is still out for me if going to Vectors is a good thing.

In mx, if I wanted to save selectedItems to the server, I just send dg.selectedItems to ColdFusion and looped through it. Simple.

In spark, I now have to covert the Vector back to an Object or ArrayCollection (since AMF rejects the Vector). Below is an example of how to loop through the Vector and convert it to a temp ArrayCollection to send to ColdFusion via RemoteObject/AMF.

var temp:ArrayCollection = new ArrayCollection();
var selIndices:Vector.<int> = dg.selectedIndices;
var selItems:Vector.<Object> = dg.selectedItems;
var numItems:Number = selIndices.length;
for (var i:Number = 0; i<numItems; i++){

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s