AdvancedDataGrid with SummaryField
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="600" height="300" >
<mx:Script>
import mx.collections.ArrayCollection;
[Bindable]
private var grocerySalesData:ArrayCollection = new ArrayCollection([
{Grocer:"A", Category:"X", Item:"Apple", Q1:15, Q2:10},
{Grocer:"A", Category:"X", Item:"Banana", Q1:25, Q2:15},
{Grocer:"A", Category:"Y", Item:"Chicken", Q1:35, Q2:42},
{Grocer:"A", Category:"Y", Item:"Beef", Q1:42, Q2:35},
{Grocer:"B", Category:"X", Item:"Apple", Q1:17, Q2:12},
{Grocer:"B", Category:"X", Item:"Pineapple", Q1:17, Q2:15},
{Grocer:"B", Category:"Y", Item:"Pork", Q1:43, Q2:43}
]);
</mx:Script>
<mx:AdvancedDataGrid id="myAdvancedDG" width="100%" height="100%" defaultLeafIcon="{null}" initialize="gc.refresh();">
<mx:dataProvider>
<mx:GroupingCollection2 id="gc" source="{grocerySalesData}">
<mx:Grouping>
<mx:GroupingField name="Grocer">
<mx:summaries>
<mx:SummaryRow summaryPlacement="group">
<mx:fields>
<mx:SummaryField dataField="Q1" label="Q1 Total" operation="SUM"/>
<mx:SummaryField dataField="Q2" label="Q2 Total" operation="SUM"/>
</mx:fields>
</mx:SummaryRow>
</mx:summaries>
</mx:GroupingField>
<mx:GroupingField name="Category">
<mx:summaries>
<mx:SummaryRow summaryPlacement="group">
<mx:fields>
<mx:SummaryField dataField="Q1" label="Q1 Total" operation="SUM"/>
<mx:SummaryField dataField="Q2" label="Q2 Total" operation="SUM"/>
</mx:fields>
</mx:SummaryRow>
</mx:summaries>
</mx:GroupingField>
</mx:Grouping>
</mx:GroupingCollection2>
</mx:dataProvider>
<mx:columns>
<mx:AdvancedDataGridColumn dataField="GroupLabel" headerText="Grocer/Category"/>
<mx:AdvancedDataGridColumn dataField="Item" headerText="Product(Item)"/>
<mx:AdvancedDataGridColumn dataField="Q1"/>
<mx:AdvancedDataGridColumn dataField="Q2"/>
<mx:AdvancedDataGridColumn dataField="Q1 Total"/>
<mx:AdvancedDataGridColumn dataField="Q2 Total"/>
</mx:columns>
</mx:AdvancedDataGrid>
</mx:Application>
Related examples in the same category