Created
February 13, 2012 18:05
-
-
Save javierguerrero/1818717 to your computer and use it in GitHub Desktop.
jQuery Tablesorter and Decimals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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