flex-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Cunliffe <mahn...@gmail.com>
Subject Re: Specific sorting, then alphabetic
Date Wed, 27 Feb 2013 08:59:57 GMT
Not sure why you are implementing your own compare. Instead I would add an
integer sort property to your code object, where the specified order is
reflected. Of your n specially sorted objects, each gets 1...n value, all
the remaining being sorted elsewhere get n+1. Then you use multiple
sortfields with the first sorting on the sort property, and the second on
your code property.

See
http://livedocs.adobe.com/flex/3/html/help.html?content=advdatagrid_03.htmland
http://www.brucephillips.name/blog/index.cfm/2006/11/23/Sort-An-ArrayCollection-By-Multiple-Fields-and-Filter-An-ArrayCollection-By-Multiple-Fields-In-Flex

happy coding
John


On Wed, Feb 27, 2013 at 9:31 AM, Shervin Asgari
<shervin.asgari@webstep.no>wrote:

> Hi.
>
> I am very very new to Flex.
> I created this thread for sorting in Java
> http://stackoverflow.com/q/15091732/37298
>
> However, I am now trying to do the same thing in ActionScript.
>
> I have a Bindable ArrayCollection with Objects that looks like this
>
> Code.code : F
> Code.label: Foo
> Code.description: The Foo description
>
> Then I want to sort exactly as specified in the stackoverflow site.
> I have around 10 of them which I need in a particular order. I have them
> defined in an array.
>
> Based on the stackoverflow question and some googling, I have come up with
> the following:
>
> private function myCompare(a:Object, b:Object, fields:Array = null):int {
>             if (mostUsed.contains(a.code) && mostUsed.contains(b.code)) {
>                 return fields.getItemIndex(a) - fields.getItemIndex(b);
>             }
>
>             if (mostUsed.contains(a.code)) {
>                 return -1;
>             }
>
>             if (mostUsed.contains(b.code)) {
>                 return 1;
>             }
>
>             var s:Sort = new Sort();
>             s.fields = fields;
>             var f:Function = s.compareFunction;
>             return f.call(null,a,b,fields);
>         }
>
> private var mostUsed:ArrayCollection = new ArrayCollection(["F", "A", "B",
> "FTR", "HIS", "KEB", "LEG", "MED", "MER", "PEN", "PEO", "PER", "PIN",
> "PUR", "REF"]);
>
> var grunner:ArrayCollection = //getting collection
> grunner.sort.fields = [new SortField("code")];
> grunner.sort.compareFunction = myCompare;
> grunner.refresh();
>
> But it doesnt work. Any clues?
> My collection returns empty.
>
> Regards Shervin
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message