<?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: 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>
	<description>A bunch of examples for Adobe Flex and ActionScript</description>
	<pubDate>Fri, 05 Dec 2008 09:38:35 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.1</generator>

	<item>
		<title>By: peterd</title>
		<link>http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/#comment-14235</link>
		<author>peterd</author>
		<pubDate>Sat, 19 Jul 2008 00:39:01 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/#comment-14235</guid>
		<description>For another example of sorting XMLListCollection, see &lt;a href="http://blog.flexexamples.com/2007/12/04/sorting-xml-documents-using-an-xmllistcollection/" rel="nofollow"&gt;"Sorting XML documents using an XMLListCollection"&lt;/a&gt;.

Peter</description>
		<content:encoded><![CDATA[<p>For another example of sorting XMLListCollection, see <a href="http://blog.flexexamples.com/2007/12/04/sorting-xml-documents-using-an-xmllistcollection/" rel="nofollow">&#8220;Sorting XML documents using an XMLListCollection&#8221;</a>.</p>
<p>Peter</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peterd</title>
		<link>http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/#comment-14233</link>
		<author>peterd</author>
		<pubDate>Fri, 18 Jul 2008 22:05:51 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/#comment-14233</guid>
		<description>vivek,

Here's an example of sorting XMLListCollection using MXML and ActionScript:

&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"&#62;

    &#60;mx:Script&#62;
        &#60;![CDATA[
            import mx.collections.SortField;
            import mx.collections.Sort;

            private function sortByField(value:String,
                        isNumeric:Boolean = false,
                        isDescending:Boolean = false):Boolean {
                var sortField:SortField = new SortField(value);
                sortField.numeric = isNumeric;
                sortField.descending = isDescending;
                var sort:Sort = new Sort();
                sort.fields = [sortField];
                xmlListColl.sort = sort;
                return xmlListColl.refresh();
            }
        ]]&#62;
    &#60;/mx:Script&#62;

    &#60;mx:XMLListCollection id="xmlListColl"&#62;
        &#60;mx:source&#62;
            &#60;mx:XMLList&#62;
                &#60;group name="Esthetique" value="2997" cost="0.52" /&#62;
                &#60;group name="xx" value="652" cost="0.47" /&#62;
                &#60;group name="xyt" value="652" cost="0.54" /&#62;
                &#60;group name="sss" value="652" cost="0.23" /&#62;
                &#60;group name="ffsdfsd" value="652" cost="0.82" /&#62;
            &#60;/mx:XMLList&#62;
        &#60;/mx:source&#62;
        &#60;mx:sort&#62;
            &#60;mx:Sort&#62;
                &#60;mx:SortField name="@cost"
                        numeric="true"
                        descending="true" /&#62;
            &#60;/mx:Sort&#62;
        &#60;/mx:sort&#62;
    &#60;/mx:XMLListCollection&#62;

    &#60;mx:Panel&#62;
        &#60;mx:DataGrid dataProvider="{xmlListColl}" width="100%"&#62;
            &#60;mx:columns&#62;
                &#60;mx:DataGridColumn dataField="@name" /&#62;
                &#60;mx:DataGridColumn dataField="@cost" /&#62;
                &#60;mx:DataGridColumn dataField="@value" /&#62;
            &#60;/mx:columns&#62;
        &#60;/mx:DataGrid&#62;
        &#60;mx:ControlBar&#62;
            &#60;mx:Button label="Sort by @name"
                    click="sortByField('@name')" /&#62;
            &#60;mx:Button label="Sort by @cost"
                    click="sortByField('@cost', true, true);" /&#62;
            &#60;mx:Button label="Sort by @value"
                    click="sortByField('@value', true, true);" /&#62;
        &#60;/mx:ControlBar&#62;
    &#60;/mx:Panel&#62;

&#60;/mx:Application&#62;
&lt;/pre&gt;

Happy Flexing!

Peter</description>
		<content:encoded><![CDATA[<p>vivek,</p>
<p>Here&#8217;s an example of sorting XMLListCollection using MXML and ActionScript:</p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"&gt;

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

            private function sortByField(value:String,
                        isNumeric:Boolean = false,
                        isDescending:Boolean = false):Boolean {
                var sortField:SortField = new SortField(value);
                sortField.numeric = isNumeric;
                sortField.descending = isDescending;
                var sort:Sort = new Sort();
                sort.fields = [sortField];
                xmlListColl.sort = sort;
                return xmlListColl.refresh();
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:XMLListCollection id="xmlListColl"&gt;
        &lt;mx:source&gt;
            &lt;mx:XMLList&gt;
                &lt;group name="Esthetique" value="2997" cost="0.52" /&gt;
                &lt;group name="xx" value="652" cost="0.47" /&gt;
                &lt;group name="xyt" value="652" cost="0.54" /&gt;
                &lt;group name="sss" value="652" cost="0.23" /&gt;
                &lt;group name="ffsdfsd" value="652" cost="0.82" /&gt;
            &lt;/mx:XMLList&gt;
        &lt;/mx:source&gt;
        &lt;mx:sort&gt;
            &lt;mx:Sort&gt;
                &lt;mx:SortField name="@cost"
                        numeric="true"
                        descending="true" /&gt;
            &lt;/mx:Sort&gt;
        &lt;/mx:sort&gt;
    &lt;/mx:XMLListCollection&gt;

    &lt;mx:Panel&gt;
        &lt;mx:DataGrid dataProvider="{xmlListColl}" width="100%"&gt;
            &lt;mx:columns&gt;
                &lt;mx:DataGridColumn dataField="@name" /&gt;
                &lt;mx:DataGridColumn dataField="@cost" /&gt;
                &lt;mx:DataGridColumn dataField="@value" /&gt;
            &lt;/mx:columns&gt;
        &lt;/mx:DataGrid&gt;
        &lt;mx:ControlBar&gt;
            &lt;mx:Button label="Sort by @name"
                    click="sortByField('@name')" /&gt;
            &lt;mx:Button label="Sort by @cost"
                    click="sortByField('@cost', true, true);" /&gt;
            &lt;mx:Button label="Sort by @value"
                    click="sortByField('@value', true, true);" /&gt;
        &lt;/mx:ControlBar&gt;
    &lt;/mx:Panel&gt;

&lt;/mx:Application&gt;
</pre>
<p>Happy Flexing!</p>
<p>Peter</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vivek</title>
		<link>http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/#comment-14217</link>
		<author>vivek</author>
		<pubDate>Fri, 18 Jul 2008 12:36:50 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/#comment-14217</guid>
		<description>Hi,

Could you please give me an example to sort numeric data in XMLListCollection? Here is my sample XML
&lt;pre class="code"&gt;
&#60;group name="Esthetique" value="2997" cost="0.52"&#62;
&#60;group name="xx" value="652" cost="0.47"&#62;
&#60;group name="xyt" value="652" cost="0.54"&#62;
&#60;group name="sss" value="652" cost="0.23"&#62;
&#60;group name="ffsdfsd" value="652" cost="0.82"&#62;
&lt;/pre&gt;

Thanks,
VIvke</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>Could you please give me an example to sort numeric data in XMLListCollection? Here is my sample XML</p>
<pre class="code">
&lt;group name="Esthetique" value="2997" cost="0.52"&gt;
&lt;group name="xx" value="652" cost="0.47"&gt;
&lt;group name="xyt" value="652" cost="0.54"&gt;
&lt;group name="sss" value="652" cost="0.23"&gt;
&lt;group name="ffsdfsd" value="652" cost="0.82"&gt;
</pre>
<p>Thanks,<br />
VIvke</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason</title>
		<link>http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/#comment-6192</link>
		<author>Jason</author>
		<pubDate>Fri, 18 Jan 2008 08:33:42 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/#comment-6192</guid>
		<description>Hi,
I to, am looking for a solution to the same problem as bader &#38; peter
(If an ArrayCollection contains a number of Foo objects and Foo has an attribute an instance of the class Bar and Bar has an attribute of fizz, can a SortField be used to sort Foo’s by the fizz attribute? I’ve tried doing new SortField(’bar.fizz’) but get a runtime error stating that bar.fizz isn’t a property of Foo — even though it is. Is there any way around this?)

You see i needed to use a itemRenderer for each column in my datagrid meaning that i had to populate each column using the code "data.etc", the problem comes into play when i want to sort a column that displays a child element of one of the objects in my arrayCollection, how do i go about doin this? Been battling for a day or two.
thanks,
jason</description>
		<content:encoded><![CDATA[<p>Hi,<br />
I to, am looking for a solution to the same problem as bader &amp; peter<br />
(If an ArrayCollection contains a number of Foo objects and Foo has an attribute an instance of the class Bar and Bar has an attribute of fizz, can a SortField be used to sort Foo’s by the fizz attribute? I’ve tried doing new SortField(’bar.fizz’) but get a runtime error stating that bar.fizz isn’t a property of Foo — even though it is. Is there any way around this?)</p>
<p>You see i needed to use a itemRenderer for each column in my datagrid meaning that i had to populate each column using the code &#8220;data.etc&#8221;, the problem comes into play when i want to sort a column that displays a child element of one of the objects in my arrayCollection, how do i go about doin this? Been battling for a day or two.<br />
thanks,<br />
jason</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bader</title>
		<link>http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/#comment-4992</link>
		<author>bader</author>
		<pubDate>Wed, 12 Dec 2007 15:11:33 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/#comment-4992</guid>
		<description>Hi,
I'm looking for the same answer for as Peter stated [is there a one..?];

peter   Oct 3rd, 2007 at 12:51 pm
If an ArrayCollection contains a number of Foo objects and Foo has an attribute an instance of the class Bar and Bar has an attribute of fizz, can a SortField be used to sort Foo’s by the fizz attribute? I’ve tried doing new SortField(’bar.fizz’) but get a runtime error stating that bar.fizz isn’t a property of Foo — even though it is. Is there any way around this?


thanks,
-bader</description>
		<content:encoded><![CDATA[<p>Hi,<br />
I&#8217;m looking for the same answer for as Peter stated [is there a one..?];</p>
<p>peter   Oct 3rd, 2007 at 12:51 pm<br />
If an ArrayCollection contains a number of Foo objects and Foo has an attribute an instance of the class Bar and Bar has an attribute of fizz, can a SortField be used to sort Foo’s by the fizz attribute? I’ve tried doing new SortField(’bar.fizz’) but get a runtime error stating that bar.fizz isn’t a property of Foo — even though it is. Is there any way around this?</p>
<p>thanks,<br />
-bader</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peterd</title>
		<link>http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/#comment-3883</link>
		<author>peterd</author>
		<pubDate>Mon, 05 Nov 2007 03:34:26 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/#comment-3883</guid>
		<description>valentineday,

I haven't tested it, but you could either try passing "false", or perhaps just comment out/delete that line altogether.

Also, if you want to do a non-case-sensitive text search, you may want to try setting the &lt;code&gt;caseInsensitive&lt;/code&gt; property to &lt;code&gt;true&lt;/code&gt;.

Peter</description>
		<content:encoded><![CDATA[<p>valentineday,</p>
<p>I haven&#8217;t tested it, but you could either try passing &#8220;false&#8221;, or perhaps just comment out/delete that line altogether.</p>
<p>Also, if you want to do a non-case-sensitive text search, you may want to try setting the <code>caseInsensitive</code> property to <code>true</code>.</p>
<p>Peter</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: valentineday</title>
		<link>http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/#comment-3880</link>
		<author>valentineday</author>
		<pubDate>Mon, 05 Nov 2007 01:06:43 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/#comment-3880</guid>
		<description>There is great!

Hey Peterd, if I want to sort by text what code should I replace for below?

dataSortField.numeric = true;

Thanks</description>
		<content:encoded><![CDATA[<p>There is great!</p>
<p>Hey Peterd, if I want to sort by text what code should I replace for below?</p>
<p>dataSortField.numeric = true;</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/#comment-3192</link>
		<author>peter</author>
		<pubDate>Wed, 03 Oct 2007 19:51:44 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/#comment-3192</guid>
		<description>If an ArrayCollection contains a number of Foo objects and Foo has an attribute an instance of the  class Bar and Bar has an attribute of fizz, can a SortField be used to sort Foo's by the fizz attribute?  I've tried doing new SortField('bar.fizz') but get a runtime error stating that bar.fizz isn't a property of Foo -- even though it is.  Is there any way around this?</description>
		<content:encoded><![CDATA[<p>If an ArrayCollection contains a number of Foo objects and Foo has an attribute an instance of the  class Bar and Bar has an attribute of fizz, can a SortField be used to sort Foo&#8217;s by the fizz attribute?  I&#8217;ve tried doing new SortField(&#8217;bar.fizz&#8217;) but get a runtime error stating that bar.fizz isn&#8217;t a property of Foo &#8212; even though it is.  Is there any way around this?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: andrei</title>
		<link>http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/#comment-187</link>
		<author>andrei</author>
		<pubDate>Tue, 14 Aug 2007 15:30:33 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/#comment-187</guid>
		<description>Thanks for the tip. Really useful. It would be also useful to know that to sort descending you need to add "dataSortField.descending = true;"

Have phun,
Andrei</description>
		<content:encoded><![CDATA[<p>Thanks for the tip. Really useful. It would be also useful to know that to sort descending you need to add &#8220;dataSortField.descending = true;&#8221;</p>
<p>Have phun,<br />
Andrei</p>
]]></content:encoded>
	</item>
</channel>
</rss>
