GroupingCollection with improved performance

There were some concerns over the performance of GroupingCollection class while grouping and calculating summaries.

So, a new class GroupingCollection2 is introduced in the data visualization components.

The major improvements in GroupingCollection2 are –
1. Grouping performance improved.
2. Summary calculation performance improved. Now, instead of looping over the data again and again, summaries are calculated in a single loop.
3. When using async refresh, the summaries are calculated as soon as each Group is built. Earlier, the summaries were calculated only after all the Groups have been made.

What has changed –
1. Introduced class GroupingCollection2 which replaces existing class GroupingCollection.
2. Introduced class SummaryField2 which replaces existing class SummaryField.

No no, classes GroupingCollection and SummaryField are not removed.
They will continue to exist to maintain backward compatibility.
So, you can use either GroupingCollection or GroupingCollection2 and AdvancedDataGrid will continue to work 🙂

The difference between SummaryField and SummaryField2 is –
SummaryField2 does not have “operation” and “summaryFunction” properties.
A new property “summaryOperation” in added in SummaryField2. It is an Object which takes one of the following –
* SUM, MIN, MAX, AVG or COUNT as String.
OR
* An implemtatation of mx.collections.ISummaryCalculator for calculating custom summaries.
The default value is SUM.

API changes –
1. Method refresh() has been changed in GroupingCollection2. The syntax now is –

function refresh(async:Boolean = false, 
		dispatchCollectionEvents:Boolean = false):Boolean;

Code changes required to start using GroupingCollection2 –
1. Use GroupingCollection2 instead of GroupingCollection.
2. Use SummaryField2 instead of SummaryField.
3. Replace operation/summaryFunction in SummaryField with summaryOperation in SummaryField2.

An example is shown here:
With GroupingCollection –

<mx:GroupingCollection id="gc" source="{arr}">
	<mx:Grouping>
		<mx:GroupingField name="name" >
			<mx:SummaryRow>
				<mx:SummaryField dataField="sal" 
					operation="MAX" />
			</mx:SummaryRow>
		</mx:GroupingField>
	</mx:Grouping>
</mx:GroupingCollection>

With GroupingCollection2 –

<mx:GroupingCollection2 id="gc" source="{arr}">
	<mx:Grouping>
		<mx:GroupingField name="name">
			<mx:SummaryRow >
				<mx:SummaryField2 dataField="sal" 
					summaryOperation="MAX" />
			</mx:SummaryRow>
		</mx:GroupingField>
	</mx:Grouping>
</mx:GroupingCollection2>

Try it and let us know your feedback.

Advertisements