On 11/14/06, 5ive <[EMAIL PROTECTED]> wrote:
>
> Couldn't find a tutorial in the Docs.
>
> Trying to implement a custom comparator function in from
> sortable_table.js
>
> function compareNatural(a, b) {
>    return a - b
> }
>
> This function returns the correct order for an array with mixed
> alphanumerics:
>
> original:       4,68,3,81,13,152,15,58a,aasd30
> string sort:   11,150,3,39,58a,aasd30,aasd55
> num sort:    "58a" cast to float becomes "NaN" and no longer possible
> to compare it with items in array
> using compareNatural():   3,11,39,58a,150,aasd30,aasd55
>
> How do I implement this function in sortable_tables.js (from the demo)?

sorttable_tables.js is not written in a way that easily accommodates
different comparators. It uses a different approach: it generates a
sortable value (such as a number, a lowercase string, a date) out of
the text, which is then sorted traditionally. You'd have to rewrite a
big chunk of it if you can't represent the order you want by such a
transformation.

The "easiest" way to implement a transformation based approach would
be to wrap the values with some wrapper object, and register a
comparator that uses your sort metric for those wrapper objects.
There's a registerComparator example in the ajax experience slides:

http://svn.mochikit.com/presentations/2006/ajax_experience/slides.html

-bob

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"MochiKit" 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/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to