[Moo] HtmlTable.Sort secondary sorting

71 views
Skip to first unread message

Maciej Trebacz

unread,
May 3, 2010, 2:38:44 PM5/3/10
to mootools-users
Hello Mootools users,

I have a question about HtmlTable.Sort. In documentation of sort() function it states that you can have secondary sorting using this class. However I couldn't guess how one can use this. Can anyone show me an example or point me in the right direction? I have a table with names and some functions, and I want to make it work when user sorts against "function", and two items has same "function" it should then sort it by "name".

--
Best regards,
Maciej "mav" Trębacz
Message has been deleted

Aaron Newton

unread,
May 5, 2010, 12:42:02 PM5/5/10
to mootool...@googlegroups.com
HtmlTable's sort functionality allows for secondary sorting, but it doesn't do this by default. If you look at the docs, the sort method takes a second argument that allows you to "prepare" a column to be a secondary sort. Here's a shell illustrating this:


Note that I sort on column 3, but the secondary sort is on the first column. 

The click handlers for the headers don't do this. You'll need to write some logic of your own to allow your users to enable a secondary sort. If it were me, I'd extend the class and overwrite the headClick method:


enjoy.

On Tue, May 4, 2010 at 5:05 AM, Axel <axel...@gmail.com> wrote:
Hello Mootools users too,

I have been wondering more less the same question...

I'm running around and looking for the right solution to do this : I
have an HtmlTable sortable by many columns. I want to set a column as
a fixed second sort option so some elements stay linked together.
- If I want to sort by Text, I'd like that first sort takes index 1
and 0 as a second sort element
- If I want to sort by Country, I'd like that first sort takes index 2
and 0 as a second sort element

The idea I first had was to use the option onSort to resort the
current Table (Table.sort()) and pass the index+reverse+prepare to do
this. But I'm wondering on the "good" idea. Would that be a good way ?

This is more less the same question as Maciej as I can't find some
examples to use onSort and prepare ...

Many thanks for your help all,

Axel.

mav

unread,
May 11, 2010, 6:05:34 AM5/11/10
to MooTools Users
Hi,

Thanks for Your reply. But I believe there's a bug in the class then.
Take a look a modified example of Yours:

http://mootools.net/shell/463Mn/9/

It's sorted first by column 1 (secondary sort) and then by column 0.
Column 0 gets sorted fine, but as You can see, in column 1 the results
are: 22, 66, 11. Which isn't sorted. Am I correct that this is a bug,
or am I doing something wrong?
Reply all
Reply to author
Forward
0 new messages