I am back trying to figure out some details of HtmlTable sorting. The
requirement is to sort descending by date. If the user selects some
other sort column, the table should be sorted by that column first,
then by descending date.
Factoring out the date for the moment, let's just talk about a two-
column table. Suppose I want to sort on column 2 descending regardless
of the direction I am sorting column 1.
Column 1 contains: 1, 2, 1, 2, 1, 2
Column 2 contains: b, c, a, b, c, a
When I click on column 1 to get an ascending sort I should get:
Column 1: 1, 1, 1, 2, 2, 2
Column 2: c, b, a, c, b, a
Sorting descending on column 1 I should get:
Column 1: 2, 2, 2, 1, 1, 1
Column 2: c, b, a, c, b, a
I have created a class called HtmlTable2 that overrides headClick so I
can catch clicks on the table header and call the sort method on my
secondary sort column with the prepare flag set (see below). The only
problem is that the sort method doesn't pay any attention to the
reverse flag unless the prepare flag is false. By repeated clicking on
the header I can sometimes get the sort direction I want, but it's not
what I was hoping for.
I suspect that I will be told to open a bug, but I wanted to report it
here first and request comments. Here's the class I am using:
HtmlTable2 = new Class({
Extends: HtmlTable,
headClick: function(event, el) {
if (el.cellIndex!=1) {
this.sort(1, true, true);
}
this.parent(event, el);
}
});