+展开-XML
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" width="460" height="428" >
<mx:Script>
<![CDATA[
import
mx.controls.advancedDataGridClasses.AdvancedDataGridItemRenderer;
import mx.collections.IGroupingCollection;
import
mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
import mx.collections.GroupingField;
import mx.collections.Grouping;
import mx.collections.ArrayCollection;
import mx.collections.GroupingCollection;
var flatData:ArrayCollection = new ArrayCollection(
[
{ Region:"Southwest", Territory:"Arizona",
Territory_Rep:"Barbara Jennings", Estimate:40000 ,
Actual:38865 },
{ Region:"Southwest", Territory:"Arizona",
Territory_Rep:"Dana Binn", Estimate:30000 ,
Actual:29885 },
{ Region:"Southwest", Territory:"Central California",
Territory_Rep:"Joe Schmoe" , Estimate:30000 ,
Actual:29134 },
{ Region:"Southwest", Territory:"Northern California" ,
Territory_Rep:"Lauren Ipsum" , Estimate:40000 ,
Actual:38805 },
{ Region:"Southwest", Territory:"Northern California" ,
Territory_Rep:"T.R. Smith" , Estimate:40000 ,
Actual:55498 },
{ Region:"Southwest", Territory:"Southern California" ,
Territory_Rep:"Jane Grove" , Estimate:45000 ,
Actual:44913 },
{ Region:"Southwest", Territory:"Southern California" ,
Territory_Rep:"Alice Treu" , Estimate:45000 ,
Actual:44985 },
{ Region:"Southwest", Territory:"Nevada" ,
Territory_Rep:"Bethany Pittman", Estimate:45000 ,
Actual:52888 }
]);
//这里AdvancedDataGrid的styleFunction属性是用来格式化显示具有summary属性的itemRenderers:
private function formatSummary(data:Object,
col:AdvancedDataGridColumn):Object
{
if (data.hasOwnProperty("summary"))
{
return { color:0xFF0000, fontWeight:"bold",
fontSize:12 };
}
return {};
}
private function flatSummaryObject():Object
{
return { Territory_Rep:"Total", summary:true };
}
]]>
</mx:Script>
<mx:AdvancedDataGrid id="adg"
creationComplete="groupedData.refresh();
adg.dataProvider.showRoot=false"
groupItemRenderer="mx.controls.advancedDataGridClasses.
AdvancedDataGridItemRenderer"
x="30" y="30" width="400" height="377"
styleFunction="formatSummary">
<mx:dataProvider>
<mx:GroupingCollection id="groupedData" source="{flatData}"
>
<mx:Grouping>
<!-- use some dummy field and set showRoot=false for
the ADG dataProvider -->
<mx:GroupingField name="fieldNameNotPresent" >
<mx:summaries>
<!-- use the summaryObjectFunction to return a
custom object which can then be used in the format function to
detect a summary row -->
<mx:SummaryRow summaryPlacement="last"
summaryObjectFunction="flatSummaryObject">
<mx:fields>
<mx:SummaryField dataField="Estimate" />
<mx:SummaryField dataField="Actual" />
</mx:fields>
</mx:SummaryRow>
</mx:summaries>
</mx:GroupingField>
</mx:Grouping>
</mx:GroupingCollection>
</mx:dataProvider>
<mx:groupedColumns>
<mx:AdvancedDataGridColumn headerText="Territory Rep"
dataField="Territory_Rep" />
<mx:AdvancedDataGridColumnGroup headerText="Sales Figures"
textAlign="center">
<mx:AdvancedDataGridColumn headerText="Estimate"
textAlign="center" dataField="Estimate"
width="100" />
<mx:AdvancedDataGridColumn headerText="Actual"
textAlign="center" dataField="Actual"
width="100" />
</mx:AdvancedDataGridColumnGroup>
</mx:groupedColumns>
</mx:AdvancedDataGrid>
</mx:Application>