jQuery.TableSorterのカスタムの件
jQuery.TableSorterのカスタムの件
http://oshiete.goo.ne.jp/qa/7696897.html
まてよ。「ヴ」って1文字じゃなくて2文字でカウントか?
(変数 dic には、長い文字列を指定しないと、例は略すぎ。)
<!DOCTYPE html> <title></title> <meta charset="UTF-8"> <body> <script> function localCharRuleSort_Create (charList, direction) { //true: 降, false:昇 direction = (!! direction) ? 1: -1; return function (a, b) { var lenA = a.length; var lenB = b.length; var len = Math.min (lenA, lenB); var charA, charB; var noA, noB; if (! isNaN (a)) { if (! isNaN (b)) { return direction * (Number (b) - Number (a)); } else { return direction; } } else if (! isNaN (b)) { return -direction; } for (var i = 0; i < len; i++) { charA = a.charAt (i); charB = b.charAt (i); if (charA === charB) continue; noA = charList.indexOf (charA); if (-1 < noA) { noB = charList.indexOf (charB); if (-1 <noB) { return direction * (noA - noB); } } return direction * (charB.charCodeAt (0) - charA.charCodeAt (0)); } return direction * (lenA < lenB); }; } var dic = "アァバヴ"; var cbFunc = localCharRuleSort_Create (dic,0); var result = [6,3,4,"バイオリン", "ヴァイオリン", "そうです", "んだぁ", 1, 3, 2].sort (cbFunc); alert("result="+result); </script>