This post is just an extension of my earlier post describing the auto sort solution for your Flex DataGrid. Upon request, I have built a simple code that demonstrates it. This is how it looks: -
The Downloads column is auto sorted and that too in descending order. The code is just pasted below (MXML and ActionScript Part): -
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script>
<![CDATA[
// Action Script goes here
]]>
</mx:Script>
<mx:DataGrid id="summary_dg" dataProvider="{dg_data.download_data}" width="400" height="120">
<mx:columns>
<mx:DataGridColumn headerText="Project Keyword and Version" dataField="keyword_version"/>
<mx:DataGridColumn headerText="Downloads" dataField="downloads" width="150" sortDescending="true"/>
</mx:columns>
</mx:DataGrid>
</mx:Application>
Action Script that should go into <mx:Script> </mx:Script>: -
import mx.events.DataGridEvent;
[Bindable]
private var dg_data:XML;
private function init():void {
dg_data =
<downloadXML>
<download_data>
<keyword_version>Product A</keyword_version>
<downloads>1000</downloads>
</download_data>
<download_data>
<keyword_version>Product B</keyword_version>
<downloads>2000</downloads>
</download_data>
<download_data>
<keyword_version>Product C</keyword_version>
<downloads>3000</downloads>
</download_data>
</downloadXML>;
summary_dg.dispatchEvent(new DataGridEvent(DataGridEvent.HEADER_RELEASE, false, true, 1, null, 0, null, null, 0));
}
Hope you find this useful.














Pingback: Auto sort of DataGrid column in FLEX | Flex Blogger