The Javascript array sort method (at least in Firefox) is apparently random within the sort.
If I have an ARRAY of OBJECTS and I sort on a particular element in the object - one that has lots of duplicates - the original order is not maintained in the final sort.
It appears random - but after a couple of clicks to sort asc and desc it does come around - so there is a pattern.
Has anyone ever dealt with this - and come up with a real solution.
I'm thinking of doing some kind of "sub-sort" on the original ordinal position prior to sort - but don't want to re-invent the wheel so that say...
Code:
function sortArray(arrSort, e, args) {
switch (e.cssClass || "") {
case "acs-cell-money":
arrSort.sort(sortNumber);
break;
case "acs-cell-number":
arrSort.sort(sortNumber);
break;
case "acs-cell-date":
arrSort.sort(sortDate);
break;
default:
arrSort.sort(comparer);
break;
}
if (!args.sortAsc) {
arrSort.reverse();
}
for (var i = 0; i < arrSort.length; i++) {
//alert(i);
arrSort[i].acsSortBits = undefined;
}
arrSort.lastMultiSort = "";
}
function comparer(a, b) {
var x = (a[sortcol.field] || "").toUpperCase();
var y = (b[sortcol.field] || "").toUpperCase();
return (x == y ? 0 : (x > y ? 1 : -1));
}