I figured it out, and this is the sortCompareFunction I ended up using:
It checks for the 3 possible conditions of a value/s being invalid. If the only one is NaN, returns 1 or -1, otherwise does a sort based on the code column.
Then if both values are valid (not NaN), does a regualar compare:
private function numericValueSort(obj1:Object, obj2:Object):int
{
var o1:NameValueObject = obj1 as NameValueObject;
var o2:NameValueObject = obj2 as NameValueObject;
if( isNaN(o1.value) && !isNaN(o2.value) ){
return 1; // o1 appears after o2;
}
if( !isNaN(o1.value) && isNaN(o2.value) ){
return -1; // o1 appears before o2
}
if( isNaN(o1.value) && isNaN(o2.value) ){
// Both values are NaN, so they will have been placed
// at the end when compared with valid values (from previous two
// IF statements, but now to compare to each other, we sort using the
// code field
return ObjectUtil.stringCompare(o1.code, o2.code);
}
// If neither value is NaN, then do a regular numeric compare
return ObjectUtil.numericCompare(o1.value, o2.value);
}