3 sortAlphaNumeric{Top,Bottom}
4 -----------------------
6 These functions are derived from sortAlphaNumeric
7 inputs are expected to be alphaNumeric values e.g. 1, e, 1a, -23c, 54z
9 when comparing two values, the following happens
10 (*) if both have a numeric part, then they are compared; if equal the non-numeric part is used
11 (*) if only one has a numeric part, then
12 . with sortAlphaNumericTop, the non-numeric value (typically n/a) happens first
13 . with sortAlphaNumericBottom, the non-numeric value (typically n/a) happens second
15 function _sortAlphaNumericPrepareData(tdNode, innerText){
16 var aa = innerText.toLowerCase().replace(" ", "");
17 var reg = /((\-|\+)?(\s+)?[0-9]+\.([0-9]+)?|(\-|\+)?(\s+)?(\.)?[0-9]+)([a-z]+)/;
20 var aaP = aa.match(reg);
21 return [aaP[1], aaP[8]];
25 return isNaN(aa) ? ["",aa] : [aa,""];
28 /* non_numeric_first :
29 when comparing, say, '12' with 'n/a':
30 if non_numeric_first is true, we return 1 (n/a greater than 12)
31 otherwise we return -1
33 function _sortAlphaNumeric(a, b, non_numeric_first) {
34 // Get the previously prepared array
35 var aa = a[fdTableSort.pos];
36 var bb = b[fdTableSort.pos];
38 // Check numeric parts if not equal
40 // both are numeric and have different numeric parts : usual comparison
41 if(aa[0] != "" && bb[0] != "") { return aa[0] - bb[0]; };
42 // one numeric value is missing
43 if(aa[0] == "" && bb[0] != "")
44 return non_numeric_first ? -1 : 1 ;
46 return non_numeric_first ? 1 : -1 ;
47 // from here and on, aa[0] == bb[0]
48 } else if (aa[1] == bb[1]) {
50 // the alpha part differ
52 return (aa[1]<bb[1] ? -1 : 1);
56 function sortAlphaNumericBottomPrepareData(tdNode, innerText) {
57 return _sortAlphaNumericPrepareData(tdNode, innerText);
59 function sortAlphaNumericBottom(a,b) {
60 return _sortAlphaNumeric (a,b,false);
62 function sortAlphaNumericTopPrepareData(tdNode, innerText) {
63 return _sortAlphaNumericPrepareData(tdNode, innerText);
65 function sortAlphaNumericTop(a,b) {
66 return _sortAlphaNumeric (a,b,true);