Rendezvous with technology

GroupingCollection with improved performance

Posted by: Sameer on: November 4, 2009

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.

12 Responses to "GroupingCollection with improved performance"

Where can we find the release. Couldn’t find anything in Adobe SVN.

Thanks

You can download Flash Builder 4 beta 2 release from http://labs.adobe.com/technologies/flashbuilder4/. This beta release contains the data visualization components with GroupingCollection2.

This remains a Flex 4 only class right? Any chance this iwll get officially backported to Flex 3? I’m using Sreenivas’s GC2 without issues but it would be nice if it was ‘offical’ http://flexpearls.blogspot.com/2008/06/groupingcollection-with-some-better.html

I don’t think these classes will be officially backported to Flex 3.x. Though, they should work if used with Flex 3.x on your own.

Copied and pasted GC2 classes into Flex3.4 with no issues. The only change I had to make was to implement labelFunction for my grouped column as Flex didnt seem to give my expand/collapse nodes a label

Hi Tom,
You can set the Grouping.label property to the dataField of the grouped column. That way, you’ll not need a labelFunction.

Cool, didnt know there was such a property, is this something new in GC2?

So, when the groups are made in GroupingCollection, the group node is stored as {GroupLabel:GROUP_NAME, …}
Now, by default the property is GroupLabel but you can change it by setting the Grouping.label property.
And yes this is present is GroupingCollection also.
The Class Grouping hasn’t changed.

So this GroupLabel I’m aware of, but its interesting how with GC (1) I saw node labels and with GC2 I didn’t. I only had the expand/collapse arrows. And my group is pretty simple as I dont use Summary Rows.

All I used to have is:
groupField1.name = “someDataField”; // this is the label in my provider

Do I need to specify columnName in ADGColumn for this to work?

As a new interface IGroupingCollection2 is introduced, there are some changes in the AdvancedDataGrid class to handle GroupingCollection2. That is why, GroupingCollection2 and Flex 4 AdvancedDataGrid works seamlessly.
But these changes are not present in the 3.4 AdvancedDataGrid and hence you have to do this workaround of setting the Grouping.label property to the same value as the column’s dataField.
You have to specify the same value for column’s dataField and Grouping.label property.

Interesting :) so can I try to copy ADG from Flex 4 into 3.x just the same? Since none of the grid components are true spark are they any more reliable? Seems like next to no work has been done to ADG in 3.x for over a year

HI Tom,
Copying ADG from Flex 4 to Flex 3.x wont work because some things are changed in Flex 4. You can search for and copy the usage of IGroupingCollection2 from Flex 4 ADG to Flex 3.x ADG.
Also, there are many bug fixes and performance improvements which have gone into Flex 3.x and Flex 4 both.

Leave a Reply