<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.1" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: 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>
	<description>A bunch of examples for Adobe Flex and ActionScript</description>
	<pubDate>Thu, 08 Jan 2009 12:16:42 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.1</generator>

	<item>
		<title>By: peterd</title>
		<link>http://blog.flexexamples.com/2008/02/28/displaying-the-sort-arrow-in-a-flex-datagrid-control-without-having-to-click-a-column/#comment-15697</link>
		<author>peterd</author>
		<pubDate>Thu, 18 Sep 2008 14:52:03 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/02/28/displaying-the-sort-arrow-in-a-flex-datagrid-control-without-having-to-click-a-column/#comment-15697</guid>
		<description>Hieu Lam,

I don't believe there is a way to show a sort arrow without refreshing the data provider. Or maybe there is, and I just don't know about it (very likely).

If you haven't found a solution yet (and are still reading comments), I suggest asking on the FlexCoders mailing list and seeing if anybody there has any ideas.

Peter</description>
		<content:encoded><![CDATA[<p>Hieu Lam,</p>
<p>I don&#8217;t believe there is a way to show a sort arrow without refreshing the data provider. Or maybe there is, and I just don&#8217;t know about it (very likely).</p>
<p>If you haven&#8217;t found a solution yet (and are still reading comments), I suggest asking on the FlexCoders mailing list and seeing if anybody there has any ideas.</p>
<p>Peter</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peterd</title>
		<link>http://blog.flexexamples.com/2008/02/28/displaying-the-sort-arrow-in-a-flex-datagrid-control-without-having-to-click-a-column/#comment-15696</link>
		<author>peterd</author>
		<pubDate>Thu, 18 Sep 2008 14:49:23 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/02/28/displaying-the-sort-arrow-in-a-flex-datagrid-control-without-having-to-click-a-column/#comment-15696</guid>
		<description>Bill J,

Not sure if this is the best solution, but it seems to work:
&lt;pre class="code"&gt;
&#60;?xml version="1.0" encoding="utf-8"?&#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.events.DataGridEvent;

            private function dataGrid_headerRelease(evt:DataGridEvent):void {
                // Hang out a while, wait a frame.
                callLater(delayedSet, [evt]);
            }

            private function delayedSet(evt:DataGridEvent):void {
                lbl1.text = evt.dataField;
                lbl2.text = dataGrid.columns[evt.columnIndex].sortDescending;
            }
        ]]&#62;
    &#60;/mx:Script&#62;

    &#60;mx:Array id="arr"&#62;
        &#60;mx:Object idx="1" c1="One.1" c2="One.2" /&#62;
        &#60;mx:Object idx="2" c1="Two.1" c2="Two.2" /&#62;
        &#60;mx:Object idx="3" c1="Three.1" c2="Three.2" /&#62;
        &#60;mx:Object idx="4" c1="Four.1" c2="Four.2" /&#62;
        &#60;mx:Object idx="5" c1="Five.1" c2="Five.2" /&#62;
        &#60;mx:Object idx="6" c1="Six.1" c2="Six.2" /&#62;
    &#60;/mx:Array&#62;

    &#60;mx:DataGrid id="dataGrid"
            dataProvider="{arr}"
            headerRelease="dataGrid_headerRelease(event);"&#62;
        &#60;mx:columns&#62;
            &#60;mx:DataGridColumn dataField="idx" /&#62;
            &#60;mx:DataGridColumn dataField="c1" /&#62;
            &#60;mx:DataGridColumn dataField="c2" /&#62;
        &#60;/mx:columns&#62;
    &#60;/mx:DataGrid&#62;

    &#60;mx:Form&#62;
        &#60;mx:FormItem label="dataField:"&#62;
            &#60;mx:Label id="lbl1" /&#62;
        &#60;/mx:FormItem&#62;
        &#60;mx:FormItem label="sortDescending:"&#62;
            &#60;mx:Label id="lbl2" /&#62;
        &#60;/mx:FormItem&#62;
    &#60;/mx:Form&#62;

&#60;/mx:Application&#62;
&lt;/pre&gt;

If you use an ArrayCollection or XMLListCollection as a data provider, you may be able to access the collection's underlying &lt;code&gt;sort&lt;/code&gt; property and determine the sort order as well.

In fact, here's what that would look like too:
&lt;pre class="code"&gt;
&#60;?xml version="1.0" encoding="utf-8"?&#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.events.DataGridEvent;

            private function dataGrid_headerRelease(evt:DataGridEvent):void {
                // Hang out a while, wait a frame.
                callLater(delayedSet, [evt]);
            }

            private function delayedSet(evt:DataGridEvent):void {
                var sortField:SortField = arrColl.sort.fields[0] as SortField;
                lbl1.text = sortField.name;
                lbl2.text = sortField.descending.toString();
            }
        ]]&#62;
    &#60;/mx:Script&#62;

    &#60;mx:ArrayCollection id="arrColl"&#62;
        &#60;mx:source&#62;
            &#60;mx:Array&#62;
                &#60;mx:Object idx="1" c1="One.1" c2="One.2" /&#62;
                &#60;mx:Object idx="2" c1="Two.1" c2="Two.2" /&#62;
                &#60;mx:Object idx="3" c1="Three.1" c2="Three.2" /&#62;
                &#60;mx:Object idx="4" c1="Four.1" c2="Four.2" /&#62;
                &#60;mx:Object idx="5" c1="Five.1" c2="Five.2" /&#62;
                &#60;mx:Object idx="6" c1="Six.1" c2="Six.2" /&#62;
            &#60;/mx:Array&#62;
        &#60;/mx:source&#62;
    &#60;/mx:ArrayCollection&#62;

    &#60;mx:DataGrid id="dataGrid"
            dataProvider="{arrColl}"
            headerRelease="dataGrid_headerRelease(event);"&#62;
        &#60;mx:columns&#62;
            &#60;mx:DataGridColumn dataField="idx" /&#62;
            &#60;mx:DataGridColumn dataField="c1" /&#62;
            &#60;mx:DataGridColumn dataField="c2" /&#62;
        &#60;/mx:columns&#62;
    &#60;/mx:DataGrid&#62;

    &#60;mx:Form&#62;
        &#60;mx:FormItem label="dataField:"&#62;
            &#60;mx:Label id="lbl1" /&#62;
        &#60;/mx:FormItem&#62;
        &#60;mx:FormItem label="sortDescending:"&#62;
            &#60;mx:Label id="lbl2" /&#62;
        &#60;/mx:FormItem&#62;
    &#60;/mx:Form&#62;

&#60;/mx:Application&#62;
&lt;/pre&gt;

Again, I make no claims this is the "best" approach, just the first thing that came to mind at 7:40am. :)

Peter</description>
		<content:encoded><![CDATA[<p>Bill J,</p>
<p>Not sure if this is the best solution, but it seems to work:</p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&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.events.DataGridEvent;

            private function dataGrid_headerRelease(evt:DataGridEvent):void {
                // Hang out a while, wait a frame.
                callLater(delayedSet, [evt]);
            }

            private function delayedSet(evt:DataGridEvent):void {
                lbl1.text = evt.dataField;
                lbl2.text = dataGrid.columns[evt.columnIndex].sortDescending;
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:Array id="arr"&gt;
        &lt;mx:Object idx="1" c1="One.1" c2="One.2" /&gt;
        &lt;mx:Object idx="2" c1="Two.1" c2="Two.2" /&gt;
        &lt;mx:Object idx="3" c1="Three.1" c2="Three.2" /&gt;
        &lt;mx:Object idx="4" c1="Four.1" c2="Four.2" /&gt;
        &lt;mx:Object idx="5" c1="Five.1" c2="Five.2" /&gt;
        &lt;mx:Object idx="6" c1="Six.1" c2="Six.2" /&gt;
    &lt;/mx:Array&gt;

    &lt;mx:DataGrid id="dataGrid"
            dataProvider="{arr}"
            headerRelease="dataGrid_headerRelease(event);"&gt;
        &lt;mx:columns&gt;
            &lt;mx:DataGridColumn dataField="idx" /&gt;
            &lt;mx:DataGridColumn dataField="c1" /&gt;
            &lt;mx:DataGridColumn dataField="c2" /&gt;
        &lt;/mx:columns&gt;
    &lt;/mx:DataGrid&gt;

    &lt;mx:Form&gt;
        &lt;mx:FormItem label="dataField:"&gt;
            &lt;mx:Label id="lbl1" /&gt;
        &lt;/mx:FormItem&gt;
        &lt;mx:FormItem label="sortDescending:"&gt;
            &lt;mx:Label id="lbl2" /&gt;
        &lt;/mx:FormItem&gt;
    &lt;/mx:Form&gt;

&lt;/mx:Application&gt;
</pre>
<p>If you use an ArrayCollection or XMLListCollection as a data provider, you may be able to access the collection&#8217;s underlying <code>sort</code> property and determine the sort order as well.</p>
<p>In fact, here&#8217;s what that would look like too:</p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&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.events.DataGridEvent;

            private function dataGrid_headerRelease(evt:DataGridEvent):void {
                // Hang out a while, wait a frame.
                callLater(delayedSet, [evt]);
            }

            private function delayedSet(evt:DataGridEvent):void {
                var sortField:SortField = arrColl.sort.fields[0] as SortField;
                lbl1.text = sortField.name;
                lbl2.text = sortField.descending.toString();
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:ArrayCollection id="arrColl"&gt;
        &lt;mx:source&gt;
            &lt;mx:Array&gt;
                &lt;mx:Object idx="1" c1="One.1" c2="One.2" /&gt;
                &lt;mx:Object idx="2" c1="Two.1" c2="Two.2" /&gt;
                &lt;mx:Object idx="3" c1="Three.1" c2="Three.2" /&gt;
                &lt;mx:Object idx="4" c1="Four.1" c2="Four.2" /&gt;
                &lt;mx:Object idx="5" c1="Five.1" c2="Five.2" /&gt;
                &lt;mx:Object idx="6" c1="Six.1" c2="Six.2" /&gt;
            &lt;/mx:Array&gt;
        &lt;/mx:source&gt;
    &lt;/mx:ArrayCollection&gt;

    &lt;mx:DataGrid id="dataGrid"
            dataProvider="{arrColl}"
            headerRelease="dataGrid_headerRelease(event);"&gt;
        &lt;mx:columns&gt;
            &lt;mx:DataGridColumn dataField="idx" /&gt;
            &lt;mx:DataGridColumn dataField="c1" /&gt;
            &lt;mx:DataGridColumn dataField="c2" /&gt;
        &lt;/mx:columns&gt;
    &lt;/mx:DataGrid&gt;

    &lt;mx:Form&gt;
        &lt;mx:FormItem label="dataField:"&gt;
            &lt;mx:Label id="lbl1" /&gt;
        &lt;/mx:FormItem&gt;
        &lt;mx:FormItem label="sortDescending:"&gt;
            &lt;mx:Label id="lbl2" /&gt;
        &lt;/mx:FormItem&gt;
    &lt;/mx:Form&gt;

&lt;/mx:Application&gt;
</pre>
<p>Again, I make no claims this is the &#8220;best&#8221; approach, just the first thing that came to mind at 7:40am. :)</p>
<p>Peter</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bill J</title>
		<link>http://blog.flexexamples.com/2008/02/28/displaying-the-sort-arrow-in-a-flex-datagrid-control-without-having-to-click-a-column/#comment-15695</link>
		<author>Bill J</author>
		<pubDate>Thu, 18 Sep 2008 14:06:59 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/02/28/displaying-the-sort-arrow-in-a-flex-datagrid-control-without-having-to-click-a-column/#comment-15695</guid>
		<description>Is there a way to programatically get the last column sort? In otherwords say the user has clicked on a particular column header, how would you store the sort associated with that header, along with its direction?</description>
		<content:encoded><![CDATA[<p>Is there a way to programatically get the last column sort? In otherwords say the user has clicked on a particular column header, how would you store the sort associated with that header, along with its direction?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hieu Lam</title>
		<link>http://blog.flexexamples.com/2008/02/28/displaying-the-sort-arrow-in-a-flex-datagrid-control-without-having-to-click-a-column/#comment-15587</link>
		<author>Hieu Lam</author>
		<pubDate>Mon, 15 Sep 2008 07:52:39 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/02/28/displaying-the-sort-arrow-in-a-flex-datagrid-control-without-having-to-click-a-column/#comment-15587</guid>
		<description>The solution is good, but I just want to know is there any way that we can showed the up/down arrow without having to refresh (sort) the grid data provider.</description>
		<content:encoded><![CDATA[<p>The solution is good, but I just want to know is there any way that we can showed the up/down arrow without having to refresh (sort) the grid data provider.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://blog.flexexamples.com/2008/02/28/displaying-the-sort-arrow-in-a-flex-datagrid-control-without-having-to-click-a-column/#comment-7233</link>
		<author>Steve</author>
		<pubDate>Fri, 29 Feb 2008 12:07:12 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/02/28/displaying-the-sort-arrow-in-a-flex-datagrid-control-without-having-to-click-a-column/#comment-7233</guid>
		<description>Thanks for this helpful post, glad to see that it's not only me that has had this problem, much appreciated, keep up the good work!</description>
		<content:encoded><![CDATA[<p>Thanks for this helpful post, glad to see that it&#8217;s not only me that has had this problem, much appreciated, keep up the good work!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
