Skip to content

Instantly share code, notes, and snippets.

@javierguerrero
Created February 13, 2012 18:05
Show Gist options
  • Save javierguerrero/1818717 to your computer and use it in GitHub Desktop.
Save javierguerrero/1818717 to your computer and use it in GitHub Desktop.
jQuery Tablesorter and Decimals
$(document).ready(function(){
$.tablesorter.addParser({
// set a unique id
id: 'versions',
is: function(s) {
// return false so this parser is not auto detected
return false;
},
format: function(s) {
// format your data for normalization
var lVersionsArray = s.split('.');
var lPower = 3;
var lPosition = 0;
var lTotal = 0;
while (lPosition < lVersionsArray.length)
{
var lFactor = Math.pow(10000, lPower);
var lValue = lVersionsArray[lPosition] * lFactor;
lTotal = lTotal + lValue;
lPower = lPower - 1;
lPosition = lPosition + 1;
}
return lTotal;
},
// set type, either numeric or text
type: 'numeric'
});
$("#versions").tablesorter({widgets: ['zebra'], headers: { 0: { sorter:'versions'}}});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment