haunsolo
07-12-2004, 03:06 PM
Hey,
I am trying to modify a script that sorts a table. The problem is that it sorts text fields correctly but is treating number fields like text and isn't sorting them correctly. So I want to write an if else statement saying that if it's a number then parseFloat it and if not then just compare as a normal string. I tried using isNan but it kept saying Object expected. The code for this function looks like this, in this state it sorts number fields correctly but does nothing to fields that are not numbers. Taking out the ParseFloat will sort text fields correctly but not numbers. How can I do both? thanks!:
function compareByColumn(nCol, bDescending) {
var c = nCol;
var d = bDescending;
function _compare(n1, n2) {
var v;
if ((parseFloat(getInnerText(n1.cells[c]))) < (parseFloat(getInnerText(n2.cells[c]))))
v = (d) ? -1 : +1;
else if (parseFloat(getInnerText(n1.cells[c])) > (parseFloat(getInnerText(n2.cells[c]))))
v = (d) ? +1 : -1;
else
v = 0;
return v;
}
return _compare;
}
I am trying to modify a script that sorts a table. The problem is that it sorts text fields correctly but is treating number fields like text and isn't sorting them correctly. So I want to write an if else statement saying that if it's a number then parseFloat it and if not then just compare as a normal string. I tried using isNan but it kept saying Object expected. The code for this function looks like this, in this state it sorts number fields correctly but does nothing to fields that are not numbers. Taking out the ParseFloat will sort text fields correctly but not numbers. How can I do both? thanks!:
function compareByColumn(nCol, bDescending) {
var c = nCol;
var d = bDescending;
function _compare(n1, n2) {
var v;
if ((parseFloat(getInnerText(n1.cells[c]))) < (parseFloat(getInnerText(n2.cells[c]))))
v = (d) ? -1 : +1;
else if (parseFloat(getInnerText(n1.cells[c])) > (parseFloat(getInnerText(n2.cells[c]))))
v = (d) ? +1 : -1;
else
v = 0;
return v;
}
return _compare;
}