mirror of
https://github.com/pfsense/pfsense.git
synced 2025-10-26 11:38:35 +00:00
Fix sortable to handle sorting of IP address columns properly. Resolves #469
This commit is contained in:
parent
8b69a3e14f
commit
bef28e2d56
@ -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 */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user