The following example shows how you can do a date sort on the Flex FileSystemDataGrid control in Adobe AIR by setting a custom sort compare function on the creationDateColumn and modificationDateColumn objects.

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication name="FileSystemDataGrid_creationDateColumn_sortCompareFunction_test"
 xmlns:mx="http://www.adobe.com/2006/mxml"
 layout="vertical"
 verticalAlign="middle"
 backgroundColor="white"
 width="600" minHeight="400">

    <mx:Script>
 <![CDATA[
 import mx.utils.ObjectUtil;

 private function init():void {
 fsdg.creationDateColumn.sortCompareFunction = createDateSortCompFunc("creationDate");
 fsdg.modificationDateColumn.sortCompareFunction = createDateSortCompFunc("modificationDate");
 }

 private function createDateSortCompFunc(sortCol:String):Function {
 return function (obj1:File, obj2:File):int { 
 return ObjectUtil.dateCompare(obj1[sortCol], obj2[sortCol]);
 }
 }
 ]]>
 </mx:Script>

    <mx:ApplicationControlBar dock="true"> 
        <mx:Label id="sdkVer" initialize="sdkVer.text = mx_internal::VERSION;" /> 
    </mx:ApplicationControlBar> 

    <mx:FileSystemDataGrid id="fsdg"
 directory="{File.userDirectory}"
 horizontalScrollPolicy="off"
 width="100%" height="100%"
 creationComplete="init();" /> 

</mx:WindowedApplication>

Alex Smirnov

Senior Java Developer. JAVA, PHP, Cold Fusion, SQL, Air, Flash.

More Posts