views:

20

answers:

1

Hi,

I have a HTML table thus:

<table id="tablesorter-demo" class="tablesorter" border="0" cellpadding="0" cellspacing="1">
    <thead>
        <tr>
            <th>Checkbox</th>
            <th>Price delta</th>
            <th>Price range</th>
            <th>Price brackets</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><input type="checkbox" id="chk1" name="chk1" value="Y" /></td>
            <td><span class="price_up">Price up</span></td>
            <td>(999.08) - (1025.67)</td>
            <td>(1025.67)</td>
        </tr>
        <tr>
            <td><input type="checkbox" id="chk2" name="chk2" value="Y" /></td>
            <td><span class="price_down">Price down</span></td>
            <td>(9.08) - (10.67)</td>
            <td>(9.08)</td>
        </tr>
        <tr>
            <td><input  type="checkbox" id="chk3" name="chk3" value="Y" /></td>
            <td><span class="price_up">Price up</span></td>
            <td>(87.48) - (92.98)</td>
            <td>(87.48)</td>
        </tr>
        <tr>
            <td><input type="checkbox" id="chk4" name="chk4" value="Y" /></td>
            <td><span class="price_up">Price up</span></td>
            <td>(1.02) - (3.45)</td>
            <td>(3.45)</td>
        </tr>
        <tr>
            <td><input type="checkbox" id="chk5" name="chk5" value="Y" /></td>
            <td><span class="price_down">Price down</span></td>
            <td>(21.01) - (72.09)</td>
            <td>(72.09)</td>
        </tr>
        <tr>
            <td><input type="checkbox" id="chk6" name="chk6" value="Y" /></td>
            <td><span class="price_up">Price up</span></td>
            <td>(875) - (900)</td>
            <td>(900)</td>
        </tr>
    </tbody>
</table>

And am trying to sort on the fourth column with the following code:

    $("#tablesorter-demo").tablesorter({
        widgets: ['zebra'],
    headers: { 
        3: { 
            sorter:'bracketedNumeric' 
        }

    }           
    });

    // add parsing for numeric in brackets 
    $.tablesorter.addParser({ 
        // set a unique id 
        id: 'bracketedNumeric', 
        is: function(s) { 
            // return false so this parser is not auto detected 
            return false; 
        }, 
        format: function(s) { 
            // format your data for normalization
            return s.Substring(s.IndexOf("(") +1, s.IndexOf(")")- s.IndexOf("(")- 1);   
        },  
        type: 'floating' 
    });

But it does not appear to be working.

A: 

Have managed to sort this with the following parser:

    // bracketed float parser
    $.tablesorter.addParser({
        // set a unique id
        id: 'floatBracket',
        is: function(s) {
            // return false so this parser is not auto detected
            return false;
        },
        format: function(s,table,cell) {
            // format your data for normalization
            var cellTxt = s.replace("(", "").replace(")", "");
            return cellTxt;
        },
        // set type, either numeric or text
        type: 'floating'
    });
RyanP13