Rendezvous with technology

Archive for the ‘Actionscript’ Category

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.

HTTPService/HTTPMultiService have a cool concept of a Serialization Filter. This mechanism let’s you configure and manipulate various aspects of the HTTP call like the request, response, etc..
A default implementation of SerializationFilter is provided in mx.rpc.http.SerializationFilter

Usage -
You can create a custom SerializationFilter by extending from the default implementation and set it on the HTTPService instance or the Operation instance.

A sample implementation can be as simple as processing the response from the service.
For example, if your service returns a comma (,) separated list of values, you can convert it to an Array here.

package
{
import mx.rpc.http.AbstractOperation;
import mx.rpc.http.SerializationFilter;

public class CustomSerializationFilter extends SerializationFilter
{	
	override public function deserializeResult
		(operation:AbstractOperation, result:Object):Object
	{
		var arr:Array = [];
		if (result is String)
		{
			arr = String(result).split(',');
		}
		return arr;
	}
}
}

And no, this is not all, there are other methods also which exposes more functionality.

For example, you can use the serializeURL() method to process/modify the url which this service/operation is about to invoke.

Livedocs here

Many times, while using RemoteObject, instead of processing the result of a remote method invocation in every result handler, you may want a mechanism to process the result before all the result handlers are notified.

convertResultHandler is such a property which was introduced in RemoteObject to process the result before sending it across to all the result handlers.

A sample implementation can be as simple as converting the result to ArrayCollection if its an Array -

public function convertResultHandler(result:*, operation:AbstractOperation):*
{
// convert result to ArrayCollection
if (result is Array)
return new ArrayCollection(result as Array);

return result;
}

Livedocs here

A similar property exists for WebService also.
Livedocs here

The new Flash Builder 4 (formerly Flex Builder) is out in its Beta. It has loads of new features. Some of them are -
Developer Productivity – Event Handler generation, Getter/setter generation code indentation, file templates, etc..
Debugging – Contitional Breakpoint, Run to line, etc..
Working with data in a brand new way (Data Centric Development) – Connecting to HTTPService, WEBService, PHP, ColdFusion, BlazeDS, LCDS has been made so easy.
Flex Unit Support.
and many more….

Useful links -
Download – http://labs.adobe.com/technologies/flashbuilder4/
What’s new – http://www.adobe.com/devnet/flex/articles/flex4builder_whatsnew.html
List of Articles – http://sujitreddyg.wordpress.com/flash-builder-4/
Don’t forget to log the issues/enhancement you encounter in the bug-base here – http://bugs.adobe.com/flex

Go ahead, download it and give us feedback to make it better.

Consider a scenario in which you want to group some data and display it in an AdvancedDataGrid. Now, you open some nodes. And you want to add summaries to the data. Adding summaries means to re-group the data by calling GroupingCollection.refresh(). But the state of open nodes will be lost as new Objects are created for the group nodes while re-grouping.

I’m posting a sample in which the open nodes are preserved.

Sample here.

Source here.

Open the sample, click on Group data, open some nodes and then click on Add Summary. The nodes which are open will remain open.

Basically, here I’m giving the same UID for the group nodes as they were before (re-grouping). That’s why, the open state is maintained.

Note: This sample will work only if the grouping fields are same for both groupings. It’ll need some tweaking in case the grouping fields are changed.

Usually people like to write the AdvancedDataGrid component in mxml. But there are some scenarios where there is a need to create the grid dynamically.

Here is a simple sample in which an AdvancedDataGrid is created dynamically with column groups.

Source is posted here.

Hello Advanced DataGrid users,

We have added a poll about AdvancedDataGrid’s performance. Please take part in the poll and help us identify the areas which needs improvement.

The poll is hosted at flexpearls

Thanks again.

In this sample, I’m using an Advanced DataGrid as an item renderer within another Advanced DataGrid. This type of configuration is very useful to give a master-detail view. This configuration can be customized more depending on any specific requirements.

Sample here

Application Source, Renderer source

Thanks to Sreeni for coming up with this.

When you set Object/Collection as a source for an AdvancedDataGrid to display the source in a Hierarchical manner, the AdvancedDataGrid.dataProvider will return an instance of IHierarchicalCollectionView because internally the source is used to construct a HierarchicalCollectionView which is returned via the dataProvider property.

What if, you want the original source from this IHierarchicalCollectionView. Well, there are some API’s for achieving this -


// First, get the HierarchicalData used to create the HierarchicalCollection
var hd:IHierarchicalData = IHierarchicalCollectionView(adg.dataProvider).source;


//From the HierarchicalData, get the source collection/object
var source:Object = hd.getRoot();

Here is a sample.
Source here.

There is a post in Flex component Yahoo group on how to show a 3-state checkbox in an AdvancedDataGrid.

It has been implemented for the Flex Tree Control in the Flex cookbook.

I thought lets write a similar example for AdvancedDataGrid. I made some changes in the original sample and here it is; working for the AdvancedDataGrid control.

Example here

Source here


Follow

Get every new post delivered to your Inbox.