Sortable table script updated to v1.5.5

I got an email from Mozilla’s director of product management Sherman Dickman today, that my sortable table script wasn’t sorting numbers above 1 million which have comma’s in them correctly (they do have a lot of Firefox downloads ;) ).

The problem was caused by the fact that replace only replaced items once, where they should be replaced multiple times. I don’t know where Sherman will be using the script yet, once I do I’ll of course tell you all about it!

15 Responses

  1. Anonymous
    By Anonymous on 28 January, 2007

    The script doesn’t work for me, I get a javascript error in your regexp in sortable.js (line 107):

    invalid quantifier +%?$

    The line is

    if (itm.match(/^-?(\d+[,\.]?)+(E[-+][\d]+)?+%?$/)) sortfn = ts_sort_numeric;

    Shouldn’t the regexp be


  2. Joost de Valk
    By Joost de Valk on 28 January, 2007

    You’re absolutely right, that’s a typo.

  3. paul
    By paul on 7 March, 2007

    I’ve been playing with sortable.js for a while on some tables I have and it works great except I can’t get it to sort number columns properly. It doesn’t seem to recognise my column as numeric and is instead searching by string (e.g. 3, 45, 9 rather than 3, 9, 45). I have the corrected JS above but still doesn’t work. Was there something special you need to do to make sure a column is viewed as number?

  4. Ole
    By Ole on 27 June, 2007


    First of all, great work, saves a lot of time and work if somebody has already developed a solution for everything you need.

    But I have a problem: I have a table in which there are dates in the German date format (such as 22.01.1950, 11.02.1951 etc.), and the script only treats them as strings and sorts them “11.02.1951 is sorted before 22.01.1950 etc.”. That is not what your script promises (and what it is programmed to do, as I think) ;). So what’s the matter? Where is my fault?

    Thanks a lot!


  5. Ole
    By Ole on 29 June, 2007

    Okay, I have found out where the problem lies:
    if (itm.match(/^-?(\d+[,\.]?)+(E[-+][\d]+)?%?$/)) sortfn = ts_sort_numeric;

    That line seems to take some dates as numbers and therefore destroys the ability of the script to sort dates. Should be changed.



  6. Eep²
    By Eep² on 1 July, 2007

    I have a very complicated table at I’d like to be able to sort, but your script doesn’t support sorting on either axis. I would like to be able to sort on the vertical axis, too, by game or feature (circa, genre, publisher, developer, etc). Also, the table has a lot of intricate column/row spanning that I’m not sure your script supports properly. As it is now, the table only sorts on the first column, screwing up majorly. :/ Can you take a look? Thanks. Oh and can the sort icons not replace existing graphics in the table cells? I had to create a separate empty table row.

  7. Jeremy Brown
    By Jeremy Brown on 10 July, 2007

    First of all fantastic script.
    Works a treat and has dropped our server load dramatically as we had page reload sorting links before.

    One point is that all our table columns have resized to equal widths. A 5 column table will set all columns to 20% rather than the default size column based on size of content.

    We have tried applying widths to each column but this hasn’t helped.
    Is this a “feature” I can disable in the script or is it just part and parcel of using this sort of dynamic functionality on a static table?

  8. Robbert de Zeeuw
    By Robbert de Zeeuw on 17 July, 2007


    The script is cool, but … ;-)

    The sorting on a date column is not working as expected; even if you see your own tabel example, the years are not sorting correctly.


  9. Robbert de Zeeuw
    By Robbert de Zeeuw on 18 July, 2007


    If you add the statement

    date = trim(date);

    at the beginning of the function function sort_date(date)

    it works for me now.

  10. Robbert de Zeeuw
    By Robbert de Zeeuw on 18 July, 2007


    My former comment was not correct!!!

    In the function ts_resortTable(lnk, clid)

    I also changed the var i from 0 into 1 (see below). Be aware of the fact that I am not an html/javascript expert, so this solution may not be the correct one.

    if (t.rows.length

  11. Oasis
    By Oasis on 20 July, 2007

    When I sort the table the Serial Number field which is the first column of the table also gets sorted. How I can fix this. I don’t want to sort my serial number column.

    Thanks in advance.

  12. Klibb
    By Klibb on 22 July, 2007

    I love this script! Is it possible to make a columm sorted by default?

  13. iGGy
    By iGGy on 31 July, 2007

    Hi. Loved this script. Works great and solved my alternate rows style problem. I have the same issue with Oasis. How to make the row number static instead of getting sorted along with the other columns?


  14. leon
    By leon on 22 August, 2007

    I don’t know why but the solution from Robbert does work :)

    I’m using the script in a system and someone had some complaints about the date field and I changed i to 1 and it works.

    Thanks for the script.

  15. Tamil
    By Tamil on 12 October, 2007

    sorttable.js is not working in mozila browser but it’s working in internet explorer give me the solution