Hi,

So to answer your questions that were asked at first :
- To sort descending an Array :
  - You sort it with the JS native function sort()
  - You use sortBy and return "-your_array.indexOf(current_element)"

- To sort alphanumeric fields :
  - It's already done by the sort function, but if you want to change
this, add/substract max values of the field in the sortBy function to
place it where you want.

All of this is theorical, it heavely depends on your data et what you
want to achieve with it. Maybe a practical example of what you wish to
accomplish could help ;)

Regards,
Julien.

On May 9, 10:04 am, "T.J. Crowder" <[email protected]> wrote:
> Hi,
>
> Sorry, I gave you a bum steer there. `sortBy` works completely
> differently from `sort`. Apparently, you only get given one element
> (and its index, as a second parameter the documentation doesn't
> mention, perhaps it's not explicitly supported) and you're meant to
> return some piece of information that will later be used to sort the
> result. (`sortBy` builds up an array of the criteria you provide, and
> then does a `sort` on it.) You have no control over the order, it will
> always be "ascending". So if you were sorting by something numeric,
> you could play games with the sign of the values you return or
> something, but you're out of luck if you're sorting based on strings
> or the like. Instead, just create your own temporary array (perhaps
> via `map`) and sort it.
>
> Sorry for the bum steer.
> --
> T.J. Crowder
> Independent Software Engineer
> tj / crowder software / com
> www / crowder software / com
>
> On May 9, 8:46 am, kstubs <[email protected]> wrote:
>
>
>
>
>
>
>
> > Thanks for the tips.  Since my posting I discovered sortBy().  So I'm close,
> > but don't see how/where to pass in the 2nd argument to compare.  I have:
>
> > list = list.sortBy(function(s) {
> >                 if(field.field.startsWith('EventScore') || field.field ==
> > 'AAScore')
> >                     return Number(Object.values(s)[index]);
> >                 else                
> >                     return Object.values(s)[index];
> >             });
>
> > Reason for the if/else is pretty straightforward; this fields beginning with
> > EventScore or AAScore are numeric.  Anyhow, how does the 2nd argument work?
> >  The above works perfectly, but strictly ascending.
>
> > Karl..

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to