以下のコードを見つけてください。
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
[Bindable]
private var dpHierarchy:ArrayCollection= new ArrayCollection([
{name:"A", region: "Arizona", number:1},
{name:"B", region: "Arizona", number:2},
{name:"C", region: "California", number:3},
{name:"D", region: "California", number:4}
]);
private function creationComp():void
{
var totalValue:int = 0;
for(var i:int=0; i<dpHierarchy.length; i++)
{
totalValue = totalValue + dpHierarchy[i].number;
}
var obj:Object = new Object();
obj.name = "Total";
obj.region = "==";
obj.number = totalValue;
dpHierarchy.addItem(obj)
myADG.dataProvider = dpHierarchy;
}
private function sortHandler(obj1:Object, obj2:Object):int
{
var lastObj:Object = dpHierarchy.getItemAt(dpHierarchy.length-1);
if(lastObj.number == obj1.number || lastObj.number == obj2.number)
return 0;
if(obj1.number < obj2.number) {
return -1;
} else if(obj1 == obj2) {
return 0;
}
return 1;
}
]]>
</fx:Script>
<mx:AdvancedDataGrid id="myADG" x="50" y="50"
width="400" height="300"
variableRowHeight="true" creationComplete="creationComp()">
<mx:columns>
<mx:AdvancedDataGridColumn dataField="name" headerText="Name" sortCompareFunction="sortHandler"/>
<mx:AdvancedDataGridColumn dataField="region" headerText="Region" sortCompareFunction="sortHandler"/>
<mx:AdvancedDataGridColumn dataField="number" headerText="Number" sortCompareFunction="sortHandler"/>
</mx:columns>
</mx:AdvancedDataGrid>
</s:Application>