我想在Javascript中使用表格排序器对表格进行排序。但是当列中有字母数字数据时,它就没有正确排序。
例如:
order1023
order1145
quote786
invoice1253
quote1010
我尝试过提供标题:{ 0: {sorter: 'text'}}, textExtraction: "complex"}
但我得到的结果是:
quote1010
order1023
order1145
invoice1253
quote786
我希望结果为
invoice1253
order1023
order1145
quote786
quote1010
答案 0 :(得分:1)
您应该添加parser,如下所示
$.tablesorter.addParser({
id: 'alphanum',
is: function(s) {
return false;
},
format: function(s) {
var str = s.replace(/(\d{1,2})/g, function(a){
return pad(a);
});
return str;
},
type: 'text'
});
function pad(num ){
var s = '00000' + num;
return s.substr(s.length-5);
}
初始化时,
$(function() {
$("table").tablesorter({
headers: {
6: { // column number
sorter:'alphanum'
}
}
});
});