Created
August 16, 2017 02:23
-
-
Save ahgood/e9651ab3469ad724f2e44539b67250ef to your computer and use it in GitHub Desktop.
Sorting by Chinese Pinyin in Datatable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
pinyin_dict_notone.js and pinyinUtil.js is available in URL below: | |
https://github.com/sxei/pinyinjs | |
*/ | |
<script src="pinyin_dict_notone.js"></script> | |
<script src="pinyinUtil.js"></script> | |
<script> | |
jQuery.extend(jQuery.fn.dataTableExt.oSort, { | |
"chinese-string-asc": function(s1, s2) { | |
s1 = pinyinUtil.getPinyin(s1); | |
s2 = pinyinUtil.getPinyin(s2); | |
return s1.localeCompare(s2); | |
}, | |
"chinese-string-desc": function(s1, s2) { | |
s1 = pinyinUtil.getPinyin(s1); | |
s2 = pinyinUtil.getPinyin(s2); | |
return s2.localeCompare(s1); | |
} | |
}); | |
jQuery(document).ready(function() { | |
jQuery('#mydatatable').dataTable({ | |
"columnDefs": [ | |
{ type: 'chinese-string', targets: 0 } | |
] | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment