[jQuery] TableSorter - Integer with Negative Values

[jQuery] TableSorter - Integer with Negative Values


I managed to get a strange bug with negative values causing the
tablesorter to sort by alpha instead of by number order.
Here's a sample HTML File Showing the sort by Alpha:
<html><head><title>TableSorter Error</title>
<script type="text/javascript" src="javascript/jquery/jquery.js"></
script>
<script type="text/javascript" src="javascript/jquery/
jquery.tablesorter.js"></script>
<script type="text/javascript">
$(document).ready(function() {
     $("#resultstable").tableSorter({
         sortColumn: 'Number'
     });
});
</script>
</head>
<body>
<table id="resultstable">
<thead>
<tr><th>Number</th></tr>
</thead>
<tbody>
<tr><td title="-6737">-7</td></tr>
<tr><td title="20000">20</td></tr>
<tr><td title="95481">95</td></tr>
<tr><td title="0">0</td></tr>
<tr><td title="15000">15</td></tr>
<tr><td title="168129">168</td></tr>
</tbody>
</table>
</body>
</html>
Notice how the sort sorts 168 right after 15...
I added this code to account for negatives and it seemed to fix the
problem.
$.tableSorter.parsers.integer.is = function(s) {
return s.match(new RegExp(/^\-[\d]+|^[\d]+$/));
};
Now it sorts negatives correctly.
Hope this helps someone, this error stymied me for awhile - It was
appearing and disappearing randomly