Filtering files based on extension type in the FileSystemDataGrid control in Adobe AIR using Flex

by Peter deHaan on December 31, 2008 · 0 comments

in FileSystemDataGrid

The following example shows how you can filter files based on file extensions in the Adobe AIR FileSystemDataGrid control by setting the extensions property.

Full code after the jump.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://airexamples.com/2008/12/31/filtering-files-based-on-extension-type-in-the-filesystemdatagrid-control-in-adobe-air-using-flex/ -->
<mx:WindowedApplication name="FileSystemDataGrid_extensions_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">
 
    <mx:Script>
        <![CDATA[
            private function init():void {
                arr = [dataGrid.nameColumn,
                        dataGrid.typeColumn,
                        dataGrid.sizeColumn];
            }
        ]]>
    </mx:Script>
 
    <mx:Array id="arr" />
 
    <mx:FileSystemDataGrid id="dataGrid"
         extensions="[mxml,xml,swf]"
         columns="{arr}"
         horizontalScrollPolicy="off"
         width="100%"
         height="100%"
         initialize="init();" />
 
</mx:WindowedApplication>

You can also set the extensions property in MXML using the <mx:extensions> tag, as seen in the following example:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://airexamples.com/2008/12/31/filtering-files-based-on-extension-type-in-the-filesystemdatagrid-control-in-adobe-air-using-flex/ -->
<mx:WindowedApplication name="FileSystemDataGrid_extensions_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">
 
    <mx:Script>
        <![CDATA[
            private function init():void {
                arr = [dataGrid.nameColumn,
                        dataGrid.typeColumn,
                        dataGrid.sizeColumn];
            }
        ]]>
    </mx:Script>
 
    <mx:Array id="arr" />
 
    <mx:FileSystemDataGrid id="dataGrid"
         columns="{arr}"
         horizontalScrollPolicy="off"
         width="100%"
         height="100%"
         initialize="init();">
        <mx:extensions>
            <mx:String>mxml</mx:String>
            <mx:String>xml</mx:String>
            <mx:String>swf</mx:String>
        </mx:extensions>
    </mx:FileSystemDataGrid>
 
</mx:WindowedApplication>

You can also set the extensions property using ActionScript, as seen in the following example:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://airexamples.com/2008/12/31/filtering-files-based-on-extension-type-in-the-filesystemdatagrid-control-in-adobe-air-using-flex/ -->
<mx:WindowedApplication name="FileSystemDataGrid_extensions_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">
 
    <mx:Script>
        <![CDATA[
            private function init():void {
                dataGrid.extensions = ['mxml', 'xml', 'swf'];
 
                arr = [dataGrid.nameColumn,
                        dataGrid.typeColumn,
                        dataGrid.sizeColumn];
            }
        ]]>
    </mx:Script>
 
    <mx:Array id="arr" />
 
    <mx:FileSystemDataGrid id="dataGrid"
         columns="{arr}"
         horizontalScrollPolicy="off"
         width="100%"
         height="100%"
         initialize="init();" />
 
</mx:WindowedApplication>

{ 0 comments… add one now }

Leave a Comment

You can 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="">

Previous post:

Next post: