Orange is my favorite color

Here’s how things should work: someone writes some open source code. You use it and like it. You see there is something that could be better. You help make it better. The cycle repeats. Everyone has better bits.

Enter TableSorter 2.0. After my previous post on TableSorter and my comments about the documentation, plugin author Christian Bach contacted me and asked if I’d help him improve the docs when 2.0 came out. My users really like the table sorting so I agreed.

The new version is great – not only is the documentation better (in my incredibly humble opinion…) but there are great new features. My personal favorite is the forced sort. My users complain when they sort by non-alpha data like timestamps and their names seems randomly ordered. Now I can fix this with the sortForce option:

$(document).ready(function() {
// call the tablesorter plugin
$("table").tablesorter({
// no matter the user selection, append a sort on the first column in ascending order
sortForce: [0,0]
});
});

My HTML tables often have last name as the first column. Even if the user sorts by other columns like order amount or registration date, TableSorter will dynamically add this sort criteria. It accomplishes the same thing as holding down shift and clicking a second column but without the user interaction. Way cool and very useful in web applications.

Kudos to Christian Bach for his great work and contribution to the jQuery community.

If you value an open source package or tool, contribute something back. It doesn’t have to be code. The real problem with the OSS community is not development resources. It’s documentation, testing and design. If we all contribute a small amount, we all win big so get on the bandwagon and make your first (or fiftieth) contribution today!

6 Comments

  1. Diego said:

    on August 18, 2007 at 2:18 am

    Hi,
    the “sortforce” is an important improvement.

    However, the script doesn’t work very well: the most important thing that the “sortforce” should do is to memorize the hierarchics criterions.

    I mean: imagine a common soccer ranking, with points, match won, loss, gol…

    For example, if two or more team with the same points have also the same gol average (COLUMN 3), the team in the first place should be the team that according to alphabetical order have an “advantage” (COLUMN, 2).
    Then the “sortforce” code should be [[3,1],[2,0]]

    Unfortunately the example doesn’t work (http://tablesorter.com/docs/example-option-sort-force.html).

    I write Christian in order to resolve this problem. Can you help me?

  2. brian said:

    on August 18, 2007 at 8:01 pm

    @Diego, at the moment, the sortForce only takes a single column to act on, unlike the sortList parameter. I chatted with Christian today and he is going to modify it to take the same parameter type as sortList so you’ll be able to handle this use case.

  3. haylo75 said:

    on August 30, 2007 at 3:59 am

    tablesorter 2.0 is amazing. Thanks for your work on the docs. They are easy to read and got me up and running in no time. I did notice what appears to be a typo in the Setting column parser using metadata example. I see “{sorter: ‘procent’}” for the discount column whereas I believe it should be “{sorter: ‘percent’}”. I didn’t see a “procent” sorter in the tablesorter code, but I did see one named “percent”.

    Quick question. If I hardcode the sorter type for each column, is there a large performance impact as opposed to allowing the detectParserForColumn method take control?

  4. brian said:

    on August 30, 2007 at 7:31 am

    @haylo75: Thanks for catching the typo, we’re going to fix that! As for setting the column parser, Christian said there would be a very small performance gain because the detect routine only looks at the first row inside the tbody. You can test for yourself by setting “debug: true” which will give statistics on everything when it runs. Let us know what you find!

  5. haylo75 said:

    on August 30, 2007 at 7:52 am

    brian – Thanks for the quick reply. I did some benchmarking using debug output and the performance difference is negligible. That makes perfect sense since the loop is for the column list of the first record.

  6. Samant said:

    on November 9, 2007 at 2:28 pm

    Hi,

    Not sure if the tablesorter still has the bug that i had found in 1.1.3 version. The bug is related to sorting of data in a table column with – sign. Eg,

    Order NO. OrderAmtDue
    1234 -0.1
    1235 -0.2
    1236 -0.12
    1237 -0.16

{ RSS feed for comments on this post}