I have several tables that I'm using tablesorter on and running into a
problem where, on some columns, it refuses to sort the column as
numbers, but insteads treats it as a string, and only sorts by the
first digit in the number. The other problem is that the column
includes a "NA" for certain fields throughout. Here's what the sorted
table looks like:

115
2
3
31
36
41
NA
NA

Obviously, not what I'm looking for. I tried writing a custom parser,
which is placed in my global.js file within a document.ready function:

// add parser through the tablesorter addParser method
    $.tablesorter.addParser({
        // set a unique id
        id: 'bignums',
        is: function(s) {
            // return false so this parser is not auto detected
            return false;
        },
        format: function(s) {
            // format your data for normalization
            if (isNAN(s)) {
                return -0.0000001;
            } else {
                    return s.replace(/,/,/./);
                }

        },
        // set type, either numeric or text
        type: 'numeric'
    });

I've tried treating it as text, with no luck. I've even gone so far as
to add the digit: ',' to the options when it's called, but it hasn't
worked.

I'm using 2.0.3, and I've tried 2.0.5. I'm also using it with the
Pager plugin, if that makes a difference, and I'm using metadata calls
in the header to tell it what sorter to use, like this:

<th style="width: 6em" class="{sorter: 'bignums'}">installs</th>

Any one got an idea? Because I'm stuck and this is the last thing I
have to knock out before it's signed off on and I get paid. I've
already spent several hours tonight on this...

Thanks!

Reply via email to