Advanced DataGrid


<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml&#8221;
layout=”vertical” creationComplete=”init()”>
<mx:Script>
<![CDATA[
import mx.collections.IHierarchicalCollectionView;

private function init():void
{
gc.refresh();
adg.dataProvider = gc;
IHierarchicalCollectionView(adg.dataProvider).openNodes = gc.getRoot();
}

// counter to maintain the uid
private var count:int = 0;

private function grpObjFunc(value:String):Object
{
// we need to assign the same uid for same grouped Objects
// use count or value + count
return {uid:value + count++};
}
]]>
</mx:Script>

<!– Source Collection –>
<mx:ArrayCollection id=”arr”>
<mx:Object name=”A” qty=”5″ cost=”100″ />
<mx:Object name=”A” qty=”10″ cost=”200″ />
<mx:Object name=”B” qty=”4″ cost=”200″ />
<mx:Object name=”C” qty=”3″ cost=”300″ />
<mx:Object name=”C” qty=”5″ cost=”350″ />
<mx:Object name=”D” qty=”2″ cost=”400″ />
<mx:Object name=”E” qty=”1″ cost=”500″ />
</mx:ArrayCollection>

<!– Grouping Collection taking source as the ArrayCollection defined above–>
<mx:GroupingCollection id=”gc” source=”{arr}”>
<mx:Grouping groupingObjectFunction=”grpObjFunc” >
<mx:fields>
<mx:GroupingField id=”gf” name=”name” />
</mx:fields>
</mx:Grouping>
</mx:GroupingCollection>

<!– Array of Summaries, to be assigned when summaries are needed –>
<mx:Array id=”summ”>
<mx:SummaryRow>
<mx:fields>
<mx:SummaryField dataField=”cost” operation=”SUM” />
</mx:fields>
</mx:SummaryRow>
</mx:Array>

<mx:AdvancedDataGrid id=”adg”   dataProvider=”{gc}” height=”300″>
<mx:columns>
<mx:AdvancedDataGridColumn  dataField=”name” />
<mx:AdvancedDataGridColumn dataField=”qty” />
<mx:AdvancedDataGridColumn dataField=”cost” />
</mx:columns>
</mx:AdvancedDataGrid>
</mx:Application>

Advertisements

~ by mjcprasad2000 on February 16, 2009.

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 )

w

Connecting to %s

 
%d bloggers like this: