diff options
author | jim-p <jim@pingle.org> | 2010-04-03 18:17:49 -0400 |
---|---|---|
committer | jim-p <jim@pingle.org> | 2010-04-03 18:18:48 -0400 |
commit | bef28e2d569302e8f9e2caaf3493dca6523eb52c (patch) | |
tree | fdc36817ae43898164e8547472021977930ae53e /usr/local/www | |
parent | 8b69a3e14f89ac68890426898d8b57bad9111bf5 (diff) | |
download | pfsense-bef28e2d569302e8f9e2caaf3493dca6523eb52c.zip pfsense-bef28e2d569302e8f9e2caaf3493dca6523eb52c.tar.gz |
Fix sortable to handle sorting of IP address columns properly. Resolves #469
Diffstat (limited to 'usr/local/www')
-rw-r--r-- | usr/local/www/javascript/sorttable.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/usr/local/www/javascript/sorttable.js b/usr/local/www/javascript/sorttable.js index 25bccb2..b7950f1 100644 --- a/usr/local/www/javascript/sorttable.js +++ b/usr/local/www/javascript/sorttable.js @@ -169,6 +169,9 @@ sorttable = { for (var i=0; i<table.tBodies[0].rows.length; i++) { text = sorttable.getInnerText(table.tBodies[0].rows[i].cells[column]); if (text != '') { + if (text.match(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/)) { + return sorttable.sort_ipaddr; + } if (text.match(/^-?[£$¤]?[\d,.]+%?$/)) { return sorttable.sort_numeric; } @@ -298,6 +301,11 @@ sorttable = { if (dt1<dt2) return -1; return 1; }, + sort_ipaddr: function(a,b) { + if (ip2ulong(a[0]) == ip2ulong(b[0])) return 0; + if (ip2ulong(a[0]) < ip2ulong(b[0])) return -1; + return 1; + }, shaker_sort: function(list, comp_func) { // A stable sort function to allow multi-level sorting of data @@ -335,6 +343,19 @@ sorttable = { Supporting functions: bundled here to avoid depending on a library ****************************************************************** */ +function ip2ulong(ip) { + ip += ""; + var ulip = false; + var octets = []; + if (ip.match(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/)) { + octets = ip.split('.'); + for (i=0; i < 4; i++) { + ulip += octets[i] * Math.pow(256, (3-i)); + } + } + return ulip; +} + // Dean Edwards/Matthias Miller/John Resig /* for Mozilla/Opera9 */ |