Sorting multi-dimensional array in JavaScript. Perused other posts, but can't figure out how to pass the array members to the custom sort function, which determines whether to sort a string or numbers. Custom sort function is this:
function colSort(a, b) {
if (sortDown) dValue = 1
else dValue = -1;
if (isNumeric(a[sortIndex])) {
return (b[sortIndex] - a[sortIndex]) * dValue;
} else {
var astring = a[sortIndex].toLowerCase();
var bstring = b[sortIndex].toLowerCase();
if (bstring > astring) return -dValue;
if (bstring < astring) return dValue;
return 0;
}
}
Array looks like this:
var qbStats =[
['David Lea', 'GB', 343, 502, 68.3, 4643, 9.2, 45, 6, 122.5],
['Kevin Whyte', 'NO', 440, 622, 70.7, 5087, 8.2, 41, 13, 108.4]
]
The column headers in a HTML table listing array members should be able to be clicked to sort ascending/descending on the clicked column.
I can't figure out how to indicate members to be sorted on the clicked index.
I know it starts as:
qbStats.sort(colSort(a,b));
But I don't know how to pass the array members to be sorted on the specific index. Ex: How do I tell it to sort on 'GB' and 'NO' as 'a' and 'b'?
Thanks for any help you can give!