Tablesorter ip address sorting problem
Hi
I'm using tablesorter in my app and it's working great except.. the ip address sorting seems to be slightly broken. It will sort on the first two groups fine, on the third group it tries to sort once and gets it wrong and on the last group it won't sort at all.
bob
After a bit of debugging the issue is that an ip address is being detected as a digit, i.e 192.168.1.100 is detected as the number 192.168 and hence only sorting on the first two groups. I fixed this by moving the digit to the end of the parsers. This is not a proper fix but works for me. Secondly the parser needs to be changed as follows. Without the debug line obviously. It was limiting each group to 2 characters and only sorting the first two groups.
Of course I could be misunderstanding the whole thing but these changes work for me.
- ts.addParser({
id: "ipAddress",
is: function (s) {
console.log("ipAddress", s, /^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}$/.test(s));
return /^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}$/.test(s);
}, format: function (s) {
var a = s.split("."),
r = "",
l = a.length;
for (var i = 0; i < 4; i++) {
var item = a[i];
if (item.length == 2) {
r += "0" + item;
} else {
r += item;
}
}
console.log(r);
return $.tablesorter.formatFloat(r);
}, type: "numeric"
});