Jquery datatable中文排序问题

来源:互联网 发布:async await python 编辑:程序博客网 时间:2024/04/29 19:16

先扩展datatable的的排序功能,添加一个自定义排序函数

//为jq datatable 自定义中文排序jQuery.fn.dataTableExt.oSort['chinese-sort-asc']  = function(s1,s2) {      return s1.localeCompare(s2);  };  jQuery.fn.dataTableExt.oSort['chinese-sort-desc'] = function(s1,s2) {      return s2.localeCompare(s1);  };   
然后将自定义字段添加到aoColumns的中文列

"aoColumns": [{"mDataProp": "id", "bSortable":false},{"mDataProp": "en_name","sType":"chinese-sort"},]
localCompare()函数会对中文按首字母排序,经在各种浏览器测试,只有搜狗浏览器存在问题

其他浏览器

'远'.localeCompare('自')//-1
搜狗

'远'.localeCompare('自')//3570


参考网址http://blog.csdn.net/wjl_mgqs/article/details/39647843




原创粉丝点击