<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flex Examples &#187; SortField</title>
	<atom:link href="http://blog.flexexamples.com/category/sortfield/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flexexamples.com</link>
	<description>Just a bunch of Adobe Flex Examples</description>
	<lastBuildDate>Wed, 26 Jan 2011 18:09:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Displaying all the properties of a component instance in Flex</title>
		<link>http://blog.flexexamples.com/2008/08/05/displaying-all-the-properties-of-a-component-instance-in-flex/</link>
		<comments>http://blog.flexexamples.com/2008/08/05/displaying-all-the-properties-of-a-component-instance-in-flex/#comments</comments>
		<pubDate>Wed, 06 Aug 2008 05:38:52 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[E4X]]></category>
		<category><![CDATA[Sort]]></category>
		<category><![CDATA[SortField]]></category>
		<category><![CDATA[TextArea]]></category>
		<category><![CDATA[XMLListCollection]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2008/08/05/displaying-all-the-properties-of-a-component-instance-in-flex/</guid>
		<description><![CDATA[<p>The following example shows you how you can display all the getters/setters and their current values for a Flex TextArea control by using the describeType() method, some E4X filtering, and an XMLListCollection.</p> <p>Full code after the jump.</p> <p></p> <p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/TextArea_accessor_test/bin/srcview/source/main.mxml.html">View MXML</a></p> &#60;?xml version="1.0" encoding="utf-8"?&#62; &#60;!-- http://blog.flexexamples.com/2008/08/05/displaying-all-the-properties-of-a-component-instance-in-flex/ --&#62; &#60;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white" creationComplete="init();"&#62; &#60;mx:Script&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows you how you can display all the getters/setters and their current values for a Flex TextArea control by using the <code>describeType()</code> method, some E4X filtering, and an XMLListCollection.</p>
<p>Full code after the jump.</p>
<p><span id="more-732"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/TextArea_accessor_test/bin/srcview/source/main.mxml.html">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2008/08/05/displaying-all-the-properties-of-a-component-instance-in-flex/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init();"&gt;

    &lt;mx:Script&gt;
        private var xmlDebug:XML;

        private function init():void {
            xmlDebug = describeType(targetObj);
            xmlListColl.source = xmlDebug.accessor.(@declaredBy == xmlDebug.@name);
        }

        private function labelFunc(item:Object, col:DataGridColumn):String {
            var value:Object = targetObj[item.@name];
            if (value == null) {
                return "(null)";
            }
            return value.toString();
        }
    &lt;/mx:Script&gt;

    &lt;mx:XMLListCollection id="xmlListColl"&gt;
        &lt;mx:sort&gt;
            &lt;mx:Sort&gt;
                &lt;mx:fields&gt;
                    &lt;mx:SortField name="@name" /&gt;
                &lt;/mx:fields&gt;
            &lt;/mx:Sort&gt;
        &lt;/mx:sort&gt;
    &lt;/mx:XMLListCollection&gt;

    &lt;mx:VDividedBox width="100%" height="100%"&gt;
        &lt;mx:TextArea id="targetObj"
                resize="init();" /&gt;

        &lt;mx:DataGrid id="dataGrid"
                dataProvider="{xmlListColl}"
                color="black"
                width="100%"
                height="100%"&gt;
            &lt;mx:columns&gt;
                &lt;mx:DataGridColumn dataField="@access"
                        itemRenderer="RedLabel" /&gt;
                &lt;mx:DataGridColumn dataField="@name" /&gt;
                &lt;mx:DataGridColumn labelFunction="labelFunc"
                        headerText="value" /&gt;
            &lt;/mx:columns&gt;
        &lt;/mx:DataGrid&gt;
    &lt;/mx:VDividedBox&gt;

&lt;/mx:Application&gt;
</pre>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/TextArea_accessor_test/bin/srcview/source/RedLabel.mxml.html">RedLabel.mxml</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2008/08/05/displaying-all-the-properties-of-a-component-instance-in-flex/ --&gt;
&lt;mx:Label xmlns:mx="http://www.adobe.com/2006/mxml" color="{(data.@access == 'readonly') ? 0xFF0000 : 0x000000}" /&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/TextArea_accessor_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/TextArea_accessor_test/bin/main.html" width="100%" height="500"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Displaying all the properties of a component instance in Flex on FlexExamples.com',url: 'http://blog.flexexamples.com/2008/08/05/displaying-all-the-properties-of-a-component-instance-in-flex/',contentID: 'post-732',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: '',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2008/08/05/displaying-all-the-properties-of-a-component-instance-in-flex/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Creating a custom sort on a DataGrid control in Flex</title>
		<link>http://blog.flexexamples.com/2008/04/09/creating-a-custom-sort-on-a-datagrid-control-in-flex/</link>
		<comments>http://blog.flexexamples.com/2008/04/09/creating-a-custom-sort-on-a-datagrid-control-in-flex/#comments</comments>
		<pubDate>Thu, 10 Apr 2008 04:12:10 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[DataGrid]]></category>
		<category><![CDATA[Sort]]></category>
		<category><![CDATA[SortField]]></category>
		<category><![CDATA[compareFunction]]></category>
		<category><![CDATA[descending]]></category>
		<category><![CDATA[sortCompareFunction]]></category>
		<category><![CDATA[stringCompare]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2008/04/09/creating-a-custom-sort-on-a-datagrid-control-in-flex/</guid>
		<description><![CDATA[<p>The following example shows how you can create a custom sort on a Flex DataGrid control by using the SortField class and creating a custom compare function.</p> <p>Full code after the jump.</p> <p></p> <p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/SortField_compareFunction_test/bin/srcview/source/main.mxml.html">View MXML</a></p> &#60;?xml version="1.0" encoding="utf-8"?&#62; &#60;!-- http://blog.flexexamples.com/2008/04/09/creating-a-custom-sort-on-a-datagrid-control-in-flex/ --&#62; &#60;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white"&#62; &#60;mx:Script&#62; &#60;![CDATA[ import mx.collections.SortField; import mx.collections.Sort; import [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how you can create a custom sort on a Flex DataGrid control by using the SortField class and creating a custom compare function.</p>
<p>Full code after the jump.</p>
<p><span id="more-590"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/SortField_compareFunction_test/bin/srcview/source/main.mxml.html">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2008/04/09/creating-a-custom-sort-on-a-datagrid-control-in-flex/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.collections.SortField;
            import mx.collections.Sort;
            import mx.controls.dataGridClasses.DataGridColumn;
            import mx.utils.ObjectUtil;

            private function sortOld():void {
                var sortField:SortField = new SortField();
                sortField.compareFunction = test2_compareFunc;
                sortField.descending = checkBox.selected;

                var oldSort:Sort = new Sort();
                oldSort.fields = [sortField];

                xmlListColl.sort = oldSort;
                xmlListColl.refresh();
            }

            private function sortNew():void {
                var sortField:SortField = new SortField();
                sortField.compareFunction = test3_compareFunc;
                sortField.descending = checkBox.selected;

                var sort:Sort = new Sort();
                sort.fields = [sortField];

                xmlListColl.sort = sort;
                xmlListColl.refresh();
            }

            private function resetSort():void {
                xmlListColl.sort = null;
                xmlListColl.refresh();
            }

            private function dataGridCol_labelFunc(item:XML, col:DataGridColumn):String {
                return item.*.(@name == col.dataField).text();
            }

            private function test2_compareFunc(itemA:XML, itemB:XML):int {
                var valueA:String = itemA.test2.text();
                var valueB:String = itemB.test2.text();
                return ObjectUtil.stringCompare(valueA, valueB);
            }

            private function test3_compareFunc(itemA:XML, itemB:XML):int {
                var valueA:String = itemA.test3.text();
                var valueB:String = itemB.test3.text();
                return ObjectUtil.stringCompare(valueA, valueB);
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:XML id="tests" source="tests.xml" /&gt;
    &lt;mx:XMLListCollection id="xmlListColl" source="{tests.test}" /&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:CheckBox id="checkBox" label="descending:" labelPlacement="left" /&gt;

        &lt;mx:Button label="Sort 'old'"
                click="sortOld();" /&gt;

        &lt;mx:Button label="Sort 'new'"
                click="sortNew();" /&gt;

        &lt;mx:Button label="Reset sort"
                click="resetSort();" /&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:DataGrid id="dataGrid"
            dataProvider="{xmlListColl}"
            width="300"
            verticalScrollPolicy="on"
            sortableColumns="true"&gt;
        &lt;mx:columns&gt;
            &lt;mx:DataGridColumn dataField="old"
                    labelFunction="dataGridCol_labelFunc"
                    sortCompareFunction="test2_compareFunc" /&gt;
            &lt;mx:DataGridColumn dataField="new"
                    labelFunction="dataGridCol_labelFunc"
                    sortCompareFunction="test3_compareFunc"  /&gt;
        &lt;/mx:columns&gt;
    &lt;/mx:DataGrid&gt;

&lt;/mx:Application&gt;</pre>
<p class="download">tests.xml</p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2008/04/09/creating-a-custom-sort-on-a-datagrid-control-in-flex/ --&gt;
&lt;tests&gt;
    &lt;test name="group1"&gt;
        &lt;test2 name="old"&gt;One (old)&lt;/test2&gt;
        &lt;test3 name="new"&gt;Un (new)&lt;/test3&gt;
    &lt;/test&gt;
    &lt;test name="group2"&gt;
        &lt;test2 name="old"&gt;Two (old)&lt;/test2&gt;
        &lt;test3 name="new"&gt;Deux (new)&lt;/test3&gt;
    &lt;/test&gt;

    &lt;test name="group8"&gt;
        &lt;test2 name="old"&gt;Eight (old)&lt;/test2&gt;
        &lt;test3 name="new"&gt;Huit (new)&lt;/test3&gt;
    &lt;/test&gt;
&lt;/tests&gt;</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/SortField_compareFunction_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/SortField_compareFunction_test/bin/main.html" width="100%" height="300"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Creating a custom sort on a DataGrid control in Flex on FlexExamples.com',url: 'http://blog.flexexamples.com/2008/04/09/creating-a-custom-sort-on-a-datagrid-control-in-flex/',contentID: 'post-590',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'compareFunction,descending,sortCompareFunction,stringCompare',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2008/04/09/creating-a-custom-sort-on-a-datagrid-control-in-flex/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Displaying the sort arrow in a Flex DataGrid control without having to click a column</title>
		<link>http://blog.flexexamples.com/2008/02/28/displaying-the-sort-arrow-in-a-flex-datagrid-control-without-having-to-click-a-column/</link>
		<comments>http://blog.flexexamples.com/2008/02/28/displaying-the-sort-arrow-in-a-flex-datagrid-control-without-having-to-click-a-column/#comments</comments>
		<pubDate>Fri, 29 Feb 2008 01:38:07 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[DataGrid]]></category>
		<category><![CDATA[Sort]]></category>
		<category><![CDATA[SortField]]></category>
		<category><![CDATA[fields]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2008/02/28/displaying-the-sort-arrow-in-a-flex-datagrid-control-without-having-to-click-a-column/</guid>
		<description><![CDATA[<p>I&#8217;ve seen this question come up a few times recently in various forums/lists and even in my blog comments (see <a href="http://blog.flexexamples.com/2008/02/23/changing-the-default-sort-arrow-skin-on-a-flex-datagrid-control/">&#8220;Changing the default sort arrow skin on a Flex DataGrid control&#8221;</a>).</p> <p>The following example shows how you can display the sort arrow in a DataGrid control in Flex without having the user click on [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve seen this question come up a few times recently in various forums/lists and even in my blog comments (see <a href="http://blog.flexexamples.com/2008/02/23/changing-the-default-sort-arrow-skin-on-a-flex-datagrid-control/">&#8220;Changing the default sort arrow skin on a Flex DataGrid control&#8221;</a>).</p>
<p>The following example shows how you can display the sort arrow in a DataGrid control in Flex without having the user click on a column header in the DataGrid control.</p>
<p>Full code after the jump.</p>
<p><span id="more-534"></span></p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- http://blog.flexexamples.com/2008/02/28/displaying-the-sort-arrow-in-a-flex-datagrid-control-without-having-to-click-a-column/ --&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Application</span> name=<span style="color: #ff0000;">&quot;DataGrid_dataProvider_sort_fields_test&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;
        layout=&quot;vertical&quot;
        verticalAlign=&quot;middle&quot;
        backgroundColor=&quot;white&quot;&gt;
&nbsp;
    <span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">        &lt;![CDATA[</span>
<span style="color: #339933;">            import mx.collections.Sort;</span>
<span style="color: #339933;">            import mx.collections.SortField;</span>
&nbsp;
<span style="color: #339933;">            private function init():void {</span>
<span style="color: #339933;">                arrColl.sort = new Sort();</span>
<span style="color: #339933;">                arrColl.sort.fields = [new SortField(&quot;idx&quot;, false, true)];</span>
<span style="color: #339933;">                arrColl.refresh();</span>
<span style="color: #339933;">            }</span>
<span style="color: #339933;">        ]]&gt;</span>
<span style="color: #339933;">    &lt;/mx:Script&gt;</span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:ArrayCollection</span> id=<span style="color: #ff0000;">&quot;arrColl&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:source</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Array</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> idx=<span style="color: #ff0000;">&quot;1&quot;</span> c1=<span style="color: #ff0000;">&quot;One.1&quot;</span> c2=<span style="color: #ff0000;">&quot;One.2&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> idx=<span style="color: #ff0000;">&quot;2&quot;</span> c1=<span style="color: #ff0000;">&quot;Two.1&quot;</span> c2=<span style="color: #ff0000;">&quot;Two.2&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> idx=<span style="color: #ff0000;">&quot;3&quot;</span> c1=<span style="color: #ff0000;">&quot;Three.1&quot;</span> c2=<span style="color: #ff0000;">&quot;Three.2&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> idx=<span style="color: #ff0000;">&quot;4&quot;</span> c1=<span style="color: #ff0000;">&quot;Four.1&quot;</span> c2=<span style="color: #ff0000;">&quot;Four.2&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> idx=<span style="color: #ff0000;">&quot;5&quot;</span> c1=<span style="color: #ff0000;">&quot;Five.1&quot;</span> c2=<span style="color: #ff0000;">&quot;Five.2&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> idx=<span style="color: #ff0000;">&quot;6&quot;</span> c1=<span style="color: #ff0000;">&quot;Six.1&quot;</span> c2=<span style="color: #ff0000;">&quot;Six.2&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> idx=<span style="color: #ff0000;">&quot;7&quot;</span> c1=<span style="color: #ff0000;">&quot;Seven.1&quot;</span> c2=<span style="color: #ff0000;">&quot;Seven.2&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> idx=<span style="color: #ff0000;">&quot;8&quot;</span> c1=<span style="color: #ff0000;">&quot;Eight.1&quot;</span> c2=<span style="color: #ff0000;">&quot;Eight.2&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> idx=<span style="color: #ff0000;">&quot;9&quot;</span> c1=<span style="color: #ff0000;">&quot;Nine.1&quot;</span> c2=<span style="color: #ff0000;">&quot;Nine.2&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> idx=<span style="color: #ff0000;">&quot;10&quot;</span> c1=<span style="color: #ff0000;">&quot;Ten.1&quot;</span> c2=<span style="color: #ff0000;">&quot;Ten.2&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> idx=<span style="color: #ff0000;">&quot;11&quot;</span> c1=<span style="color: #ff0000;">&quot;Eleven.1&quot;</span> c2=<span style="color: #ff0000;">&quot;Eleven.2&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> idx=<span style="color: #ff0000;">&quot;12&quot;</span> c1=<span style="color: #ff0000;">&quot;Twelve.1&quot;</span> c2=<span style="color: #ff0000;">&quot;Twelve.2&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> idx=<span style="color: #ff0000;">&quot;13&quot;</span> c1=<span style="color: #ff0000;">&quot;Thirteen.1&quot;</span> c2=<span style="color: #ff0000;">&quot;Thirteen.2&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Array</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:source</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:ArrayCollection</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:DataGrid</span> id=<span style="color: #ff0000;">&quot;dataGrid&quot;</span></span>
<span style="color: #000000;">            dataProvider=<span style="color: #ff0000;">&quot;{arrColl}&quot;</span></span>
<span style="color: #000000;">            creationComplete=<span style="color: #ff0000;">&quot;init();&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:columns</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:DataGridColumn</span> dataField=<span style="color: #ff0000;">&quot;idx&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:DataGridColumn</span> dataField=<span style="color: #ff0000;">&quot;c1&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:DataGridColumn</span> dataField=<span style="color: #ff0000;">&quot;c2&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:columns</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:DataGrid</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/DataGrid_dataProvider_sort_fields_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/DataGrid_dataProvider_sort_fields_test/bin/main.html" width="100%" height="220"></iframe></p>
<p>A big thanks to Rob for the heads up with the solution!</p>
<p>For more information, see <a href="http://bugs.adobe.com/jira/browse/SDK-14663">http://bugs.adobe.com/jira/browse/SDK-14663</a>.</p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Displaying the sort arrow in a Flex DataGrid control without having to click a column on FlexExamples.com',url: 'http://blog.flexexamples.com/2008/02/28/displaying-the-sort-arrow-in-a-flex-datagrid-control-without-having-to-click-a-column/',contentID: 'post-534',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'fields',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2008/02/28/displaying-the-sort-arrow-in-a-flex-datagrid-control-without-having-to-click-a-column/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>Creating a custom label function on a Flex PopUpMenuButton control</title>
		<link>http://blog.flexexamples.com/2008/02/21/creating-a-custom-label-function-on-a-flex-popupmenubutton-control/</link>
		<comments>http://blog.flexexamples.com/2008/02/21/creating-a-custom-label-function-on-a-flex-popupmenubutton-control/#comments</comments>
		<pubDate>Fri, 22 Feb 2008 05:42:33 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[PopUpMenuButton]]></category>
		<category><![CDATA[SortField]]></category>
		<category><![CDATA[dataProvider]]></category>
		<category><![CDATA[labelFunction]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2008/02/21/creating-a-custom-label-function-on-a-flex-popupmenubutton-control/</guid>
		<description><![CDATA[<p>The following example shows how you can use an XML data provider on a PopUpMenuButton in Flex and create a custom label function using the labelFunction property.</p> <p>Full code after the jump.</p> <p></p> <p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/PopUpMenuButton_labelFunction_test/main.mxml">View MXML</a></p> &#60;?xml version="1.0" encoding="utf-8"?&#62; &#60;!-- http://blog.flexexamples.com/2008/02/21/creating-a-custom-label-function-on-a-flex-popupmenubutton-control/ --&#62; &#60;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="top" backgroundColor="white"&#62; &#60;mx:Script&#62; &#60;![CDATA[ private function getTeams(dp:XML, leagueAbbrev:String, divisionLabel:String):XMLList [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how you can use an XML data provider on a PopUpMenuButton in Flex and create a custom label function using the <code>labelFunction</code> property.</p>
<p>Full code after the jump.</p>
<p><span id="more-527"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/PopUpMenuButton_labelFunction_test/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2008/02/21/creating-a-custom-label-function-on-a-flex-popupmenubutton-control/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="top"
        backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            private function getTeams(dp:XML, leagueAbbrev:String, divisionLabel:String):XMLList {
                return dp.league.(@abbrev == leagueAbbrev).division.(@label == divisionLabel).team;
            }

            private function popUpMenuButton_labelFunc(item:Object):String {
                return item.@label + " " + item.@name;
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:XML id="mlb" source="mlb.xml" /&gt;

    &lt;mx:XMLListCollection id="mlbXLC"
            source="{getTeams(mlb, 'NL', 'West')}"&gt;
        &lt;mx:sort&gt;
            &lt;mx:Sort&gt;
                &lt;mx:fields&gt;
                    &lt;mx:SortField name="@label"
                            caseInsensitive="true" /&gt;
                &lt;/mx:fields&gt;
            &lt;/mx:Sort&gt;
        &lt;/mx:sort&gt;
    &lt;/mx:XMLListCollection&gt;

    &lt;mx:PopUpMenuButton id="popUpMenuButton"
            dataProvider="{mlbXLC}"
            labelFunction="popUpMenuButton_labelFunc" /&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/PopUpMenuButton_labelFunction_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/PopUpMenuButton_labelFunction_test/bin/main.html" width="100%" height="300"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Creating a custom label function on a Flex PopUpMenuButton control on FlexExamples.com',url: 'http://blog.flexexamples.com/2008/02/21/creating-a-custom-label-function-on-a-flex-popupmenubutton-control/',contentID: 'post-527',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'dataProvider,labelFunction',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2008/02/21/creating-a-custom-label-function-on-a-flex-popupmenubutton-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sorting XML documents using an XMLListCollection</title>
		<link>http://blog.flexexamples.com/2007/12/04/sorting-xml-documents-using-an-xmllistcollection/</link>
		<comments>http://blog.flexexamples.com/2007/12/04/sorting-xml-documents-using-an-xmllistcollection/#comments</comments>
		<pubDate>Wed, 05 Dec 2007 07:41:08 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[Sort]]></category>
		<category><![CDATA[SortField]]></category>
		<category><![CDATA[XMLListCollection]]></category>
		<category><![CDATA[fields]]></category>
		<category><![CDATA[reverse()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/12/04/sorting-xml-documents-using-an-xmllistcollection/</guid>
		<description><![CDATA[<p>The following example shows how you can sort an XML document by converting it into an XMLListCollection and applying a sort. You can also easily reverse the current sort by calling the SortField object&#8217;s reverse() method and refreshing the XMLListCollection object.</p> <p>Full code after the jump.</p> <p></p> <p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/XMLListCollection_sort_test/main.mxml">View MXML</a></p> &#60;?xml version="1.0" encoding="utf-8"?&#62; &#60;!-- [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how you can sort an XML document by converting it into an XMLListCollection and applying a sort. You can also easily reverse the current sort by calling the SortField object&#8217;s <code>reverse()</code> method and refreshing the XMLListCollection object.</p>
<p>Full code after the jump.</p>
<p><span id="more-351"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/XMLListCollection_sort_test/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/12/04/sorting-xml-documents-using-an-xmllistcollection/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.utils.StringUtil;

            private function list_labelFunc(item:Object):String {
                return StringUtil.substitute("{0} {1} ({2} {3})",
                        item.@label, // city
                        item.@name, // name
                        item.parent().parent().@abbrev, // league
                        item.parent().@label); // division
            }

            private function checkBox_click(evt:MouseEvent):void {
                sortField.reverse();
                xmlListColl.refresh();
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:XML id="mlb" source="mlb.xml" /&gt;

    &lt;mx:XMLListCollection id="xmlListColl"
            source="{mlb.league.division.team}"&gt;
        &lt;mx:sort&gt;
            &lt;mx:Sort&gt;
                &lt;mx:fields&gt;
                    &lt;mx:SortField id="sortField"
                            name="@label"
                            caseInsensitive="true" /&gt;
                &lt;/mx:fields&gt;
            &lt;/mx:Sort&gt;
        &lt;/mx:sort&gt;
    &lt;/mx:XMLListCollection&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:CheckBox id="checkBox"
                label="reverse()"
                labelPlacement="left"
                click="checkBox_click(event);" /&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:List id="list"
            dataProvider="{xmlListColl}"
            labelFunction="list_labelFunc"
            width="300"
            rowCount="8" /&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/XMLListCollection_sort_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/XMLListCollection_sort_test/bin/main.html" width="100%" height="280"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Sorting XML documents using an XMLListCollection on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/12/04/sorting-xml-documents-using-an-xmllistcollection/',contentID: 'post-351',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'fields,reverse()',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2007/12/04/sorting-xml-documents-using-an-xmllistcollection/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Sorting and filtering data in an XMLListCollection</title>
		<link>http://blog.flexexamples.com/2007/08/22/sorting-and-filtering-data-in-an-xmllistcollection/</link>
		<comments>http://blog.flexexamples.com/2007/08/22/sorting-and-filtering-data-in-an-xmllistcollection/#comments</comments>
		<pubDate>Thu, 23 Aug 2007 06:58:39 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[Sort]]></category>
		<category><![CDATA[SortField]]></category>
		<category><![CDATA[XMLListCollection]]></category>
		<category><![CDATA[describeType()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/22/sorting-and-filtering-data-in-an-xmllistcollection/</guid>
		<description><![CDATA[<p>The following code is a brief example of sorting a Flex XMLListCollection using the Sort and SortField classes, and the XMLListCollection.sort property. We also look at filtering the XMLCollection using a custom filter function.</p> <p>Full code after the jump.</p> <p></p> <p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/XMLListCollection_filterFunction_test_2/main.mxml">View MXML</a></p> &#60;?xml version="1.0" encoding="utf-8"?&#62; &#60;!-- http://blog.flexexamples.com/2007/08/22/sorting-and-filtering-data-in-an-xmllistcollection/ --&#62; &#60;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white" [...]]]></description>
			<content:encoded><![CDATA[<p>The following code is a brief example of sorting a Flex XMLListCollection using the Sort and SortField classes, and the <code>XMLListCollection.sort</code> property. We also look at filtering the XMLCollection using a custom filter function.</p>
<p>Full code after the jump.</p>
<p><span id="more-85"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/XMLListCollection_filterFunction_test_2/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/08/22/sorting-and-filtering-data-in-an-xmllistcollection/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init()"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.collections.SortField;
            import mx.collections.Sort;
            import mx.controls.*;

            private function init():void {
                describeTypeXML = describeType(DataGrid);
                factoryMethodsXLC.source = describeTypeXML.factory.method;
            }

            private function sortXLC():void {
                var nameSort:Sort = new Sort();
                nameSort.fields = [new SortField('@name', true)];

                factoryMethodsXLC.sort = nameSort;
                factoryMethodsXLC.refresh();
            }

            private function filterXLC():void {
                if (filterCh.selected) {
                    factoryMethodsXLC.filterFunction = declaredBy_filterFunc;
                    factoryMethodsXLC.refresh();
                } else {
                    factoryMethodsXLC.filterFunction = null;
                    factoryMethodsXLC.refresh();
                }
            }

            private function declaredBy_filterFunc(item:XML):Boolean {
                return item.@declaredBy == describeTypeXML.@name;
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:XML id="describeTypeXML" /&gt;

    &lt;mx:XMLListCollection id="factoryMethodsXLC" /&gt;

    &lt;mx:VBox&gt;
        &lt;mx:DataGrid id="factoryMethodsGrid"
                dataProvider="{factoryMethodsXLC}"
                width="400"
                rowCount="7"&gt;
            &lt;mx:columns&gt;
                &lt;mx:DataGridColumn dataField="@name" /&gt;
                &lt;mx:DataGridColumn dataField="@returnType" /&gt;
                &lt;mx:DataGridColumn dataField="@declaredBy" /&gt;
            &lt;/mx:columns&gt;
        &lt;/mx:DataGrid&gt;
        &lt;mx:HBox width="100%"&gt;
            &lt;mx:Button id="sortBtn"
                    label="Sort ({factoryMethodsGrid.dataProvider.length} items)"
                    click="sortXLC()" /&gt;
            &lt;mx:Spacer width="100%" /&gt;
            &lt;mx:CheckBox id="filterCh"
                    label="{describeTypeXML.@name} only"
                    click="filterXLC()" /&gt;
        &lt;/mx:HBox&gt;
    &lt;/mx:VBox&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/XMLListCollection_filterFunction_test_2/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/XMLListCollection_filterFunction_test_2/bin/main.html" width="100%" height="300"></iframe></p>
<p>Apparently this post has been sitting quietly in my drafts folder for so long I can&#8217;t even remember writing it, but hopefully it helps somebody out there.</p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Sorting and filtering data in an XMLListCollection on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/08/22/sorting-and-filtering-data-in-an-xmllistcollection/',contentID: 'post-85',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'describeType()',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2007/08/22/sorting-and-filtering-data-in-an-xmllistcollection/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Sorting an XMLListCollection using the mx:Sort and mx:SortField MXML tags</title>
		<link>http://blog.flexexamples.com/2007/08/15/sorting-an-xmllistcollection-using-the-mxsort-and-mxsortfield-mxml-tags/</link>
		<comments>http://blog.flexexamples.com/2007/08/15/sorting-an-xmllistcollection-using-the-mxsort-and-mxsortfield-mxml-tags/#comments</comments>
		<pubDate>Thu, 16 Aug 2007 07:40:53 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[Sort]]></category>
		<category><![CDATA[SortField]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XMLListCollection]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/15/sorting-an-xmllistcollection-using-the-mxsort-and-mxsortfield-mxml-tags/</guid>
		<description><![CDATA[<p>I actually searched around and couldn&#8217;t find any other examples of this, but here is a quick example of using the &#60;mx:Sort /&#62; and &#60;mx:SortField /&#62; MXML tags in Flex to sort an XMLListCollection.</p> <p>Full code after the jump.</p> <p></p> <p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/XMLListCollection_sort_test_2/main.mxml">View MXML</a></p> &#60;?xml version="1.0" encoding="utf-8"?&#62; &#60;!-- http://blog.flexexamples.com/2007/08/15/sorting-an-xmllistcollection-using-the-mxsort-and-mxsortfield-mxml-tags/ --&#62; &#60;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white"&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>I actually searched around and couldn&#8217;t find any other examples of this, but here is a quick example of using the &lt;mx:Sort /&gt; and &lt;mx:SortField /&gt; MXML tags in Flex to sort an XMLListCollection.</p>
<p>Full code after the jump.</p>
<p><span id="more-89"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/XMLListCollection_sort_test_2/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/08/15/sorting-an-xmllistcollection-using-the-mxsort-and-mxsortfield-mxml-tags/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:XML id="myXML" source="http://feeds.feedburner.com/FlexExamples?format=xml" format="e4x" /&gt;
    &lt;mx:XMLListCollection id="xlc" source="{myXML..item.category}" sort="{mySort}" /&gt;

    &lt;mx:Sort id="mySort"&gt;
        &lt;mx:fields&gt;
            &lt;mx:SortField name="*" caseInsensitive="true" /&gt;
        &lt;/mx:fields&gt;
    &lt;/mx:Sort&gt;

    &lt;mx:VBox horizontalAlign="left"&gt;
        &lt;mx:Label text="Categories ({xlc.length}):" /&gt;
        &lt;mx:List id="list"
                dataProvider="{xlc}"
                rowCount="5"
                width="200"
                creationComplete="{xlc.refresh()}" /&gt;
    &lt;/mx:VBox&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/XMLListCollection_sort_test_2/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/XMLListCollection_sort_test_2/bin/main.html" width="100%" height="200"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Sorting an XMLListCollection using the mx:Sort and mx:SortField MXML tags on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/08/15/sorting-an-xmllistcollection-using-the-mxsort-and-mxsortfield-mxml-tags/',contentID: 'post-89',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: '',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2007/08/15/sorting-an-xmllistcollection-using-the-mxsort-and-mxsortfield-mxml-tags/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Sorting an ArrayCollection using the SortField and Sort classes</title>
		<link>http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/</link>
		<comments>http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/#comments</comments>
		<pubDate>Sun, 05 Aug 2007 15:18:48 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ArrayCollection]]></category>
		<category><![CDATA[Sort]]></category>
		<category><![CDATA[SortField]]></category>
		<category><![CDATA[fields]]></category>
		<category><![CDATA[refresh()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/</guid>
		<description><![CDATA[<p>Sometimes in life you just need data to be sorted. Whether its a case insensitive sort (for names) or a numeric sort (for, uh, numbers), you just want things sorted in a particular order.</p> <p>This example demonstrates how you can take a bunch of random numbers in an ArrayCollection and sort them numerically in ascending [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes in life you just need data to be sorted. Whether its a case insensitive sort (for names) or a numeric sort (for, uh, numbers), you just want things sorted in a particular order.</p>
<p>This example demonstrates how you can take a bunch of random numbers in an ArrayCollection and sort them numerically in ascending order.</p>
<p><span id="more-56"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/ArrayCollection_sort_test/bin/srcview/ArrayCollection_sort_test.zip">Download source (ZIP, 1K)</a> | <a href="http://blog.flexexamples.com/wp-content/uploads/ArrayCollection_sort_test/main.mxml">View MXML</a></p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Application</span> xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> layout=<span style="color: #ff0000;">&quot;vertical&quot;</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span> backgroundColor=<span style="color: #ff0000;">&quot;white&quot;</span> creationComplete=<span style="color: #ff0000;">&quot;init()&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">        &lt;![CDATA[</span>
<span style="color: #339933;">            import mx.collections.SortField;</span>
<span style="color: #339933;">            import mx.collections.Sort;</span>
<span style="color: #339933;">            import mx.collections.ArrayCollection;</span>
&nbsp;
<span style="color: #339933;">            [Bindable]</span>
<span style="color: #339933;">            private var arrColl:ArrayCollection;</span>
&nbsp;
<span style="color: #339933;">            /** This method gets called by the main mx:Application tag and initializes/populates the ArrayCollection object with a bunch of random numbers. */</span>
<span style="color: #339933;">            private function init():void {</span>
<span style="color: #339933;">                var i:int;</span>
&nbsp;
<span style="color: #339933;">                /* Initialize and populate the ArrayCollection object. */</span>
<span style="color: #339933;">                arrColl = new ArrayCollection();</span>
<span style="color: #339933;">                for (i = 0; i &lt; 20; i++) {</span>
<span style="color: #339933;">                    arrColl.addItem({data:getRandomNumber().toFixed(4)});</span>
<span style="color: #339933;">                }</span>
<span style="color: #339933;">            }</span>
&nbsp;
<span style="color: #339933;">            /** This method returns a random floating-point number between 0 and 10000. */</span>
<span style="color: #339933;">            private function getRandomNumber():Number {</span>
<span style="color: #339933;">                return Math.random() * 10000;</span>
<span style="color: #339933;">            }</span>
&nbsp;
<span style="color: #339933;">            /** This method gets called by the Button control's click handler and creates a new SortField and Sort object which are used to sort the ArrayCollection. */</span>
<span style="color: #339933;">            private function button_click():void {</span>
<span style="color: #339933;">                /* Create the SortField object for the &quot;data&quot; field in the ArrayCollection object, and make sure we do a numeric sort. */</span>
<span style="color: #339933;">                var dataSortField:SortField = new SortField();</span>
<span style="color: #339933;">                dataSortField.name = &quot;data&quot;;</span>
<span style="color: #339933;">                dataSortField.numeric = true;</span>
&nbsp;
<span style="color: #339933;">                /* Create the Sort object and add the SortField object created earlier to the array of fields to sort on. */</span>
<span style="color: #339933;">                var numericDataSort:Sort = new Sort();</span>
<span style="color: #339933;">                numericDataSort.fields = [dataSortField];</span>
&nbsp;
<span style="color: #339933;">                /* Set the ArrayCollection object's sort property to our custom sort, and refresh the ArrayCollection. */</span>
<span style="color: #339933;">                arrColl.sort = numericDataSort;</span>
<span style="color: #339933;">                arrColl.refresh();</span>
<span style="color: #339933;">            }</span>
<span style="color: #339933;">        ]]&gt;</span>
<span style="color: #339933;">    &lt;/mx:Script&gt;</span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:List</span> id=<span style="color: #ff0000;">&quot;list&quot;</span> dataProvider=<span style="color: #ff0000;">&quot;{arrColl}&quot;</span> textAlign=<span style="color: #ff0000;">&quot;right&quot;</span> labelField=<span style="color: #ff0000;">&quot;data&quot;</span> width=<span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> id=<span style="color: #ff0000;">&quot;button&quot;</span> label=<span style="color: #ff0000;">&quot;sort items&quot;</span> click=<span style="color: #ff0000;">&quot;button_click()&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p class="information">View source is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/ArrayCollection_sort_test/bin/main.html" width="100%" height="250"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Sorting an ArrayCollection using the SortField and Sort classes on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/',contentID: 'post-56',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'fields,refresh()',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/feed/</wfw:commentRss>
		<slash:comments>38</slash:comments>
		</item>
	</channel>
</rss>

