Not yet rated

Problem

I new to add some rows that will have sub-totals to a Datagrid, having a special pattern. How can I do this

Solution

Use the SummaryField class to sum a column.

Detailed explanation

Import the included Flex project and view ADG_4_Summaries.mxml for the working code.

 

The important code is early on in the file:
                var sr:SummaryRow = new SummaryRow();
                var sf:SummaryField = new SummaryField("hours");
                sf.label = "hourssummary";
                sr.fields = [sf];
                gf.summaries = [sr];
 

We create a summary row, then a field.  The field is passed a string that references the property on each row that it should be summarizing.  We define 'label' for the SummaryField that will create a new dataField that can be rendered.  Finally we hook the field and summaries up to the groups.

Later on, in our ADG, we supply a rendererprovider that will give the summary it's own line.  The renderer is very simple, just inherting from Label and adding some text.

            <mx:AdvancedDataGridRendererProvider dataField="hourssummary"
                                                 depth="2"
                                                 columnIndex="0"
                                                 columnSpan="0"
                                                 renderer="HourSummaryRenderer"/>
 


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes