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"?>
<!-- http://airexamples.com/2010/03/10/sorting-the-filesystemdatagrid-control-by-date-in-adobe-air/ -->
<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>

2 Responses to Sorting the FileSystemDataGrid control by date in Adobe AIR

  1. jeff says:

    is there a way to keep whatever sort was clicked as user change directories?

  2. jeff says:

    so as they navigate back if they sorted in those directories the sort will remain?

    by default it doesnt keep it

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Spam Protection by WP-SpamFree