du*******@yahoo.com wrote:
I am very new to Javascript, and have some problems with the code for
sorting. My question is in the following web page: [...]
Untested quickhack for IDs matching /\D+-\d+/:
function sortByID(a, b) {
var A = a["ID"].toLowerCase().replace(/\d/g,""),
B = b["ID"].toLowerCase().replace(/\d/g,""),
C = a["ID"].replace(/\D/g,""),
D = b["ID"].replace(/\D/g,"");
if (A < B) return -1;
else if (A > B) return 1;
else if (C - D < 0) return -1;
else if (C - D > 0) return 1;
else return 0;
}
In addition to that, you should test if a function exists that
is named like the value you get from the location's search before
you call it:
var sortCriteria = location.search.substring(1);
if (sortCriteria && typeof window[sortCriteria] == "function")
kidney.sort(window[sortCriteria]);
ciao, dhgm