views:

502

answers:

1

I have a sorted table of results for a sporting event. When I click a header, I want to sort from best to worst, always. I don't want it to reverse when I click again. In some cases the "best" is the shortest amount of time, and other case the "best" is the largest amount (i.e. most weight, longest distance). I have had little luck so far.

+1  A: 

Never used tablesorter before, but taking a quick look, it doesn't seem like it does what you want it to do out of the box. Here are a couple of (untested) hacks I came up with:

One way (short of modifying the plugin source) would be to pick up on this example and add a click event handler to your header cells to trigger your sort using a defined order. You might have to remove the handler that the tablesorter plugin added, or return false from your handler, to avoid sorting twice.

Alternatively, if you're not afraid to change the plugin source, it looks like line 536 is the one you want:

// get current column sort order
this.order = this.count++ % 2;

Replace this.count++ % 2 with 0 for ascending, 1 for descending. You could also make it more robust by adding a "forced order" as an option (see lines 94-114), perhaps even making it into an array (like sortList) to indicate which columns should have the order forced.

Good luck!

Matt Winckler
Yeah thats pretty much what I was looking at, just wanted to see if there was any other way of doing it... thanks.
ryanrdl
and here's another tip, I guess, as I needed this functionality myself... getting that sort DESC the first time around but being able to resort ASC on the next click, just change that line to:this.order = ++this.count % 2;
Crazy Serb