jQuery 1.7.1 和 tablesorter 插件 - 我有一个带有千位分隔符的货币列和类似 $52.00 $26.70 $100.00 $50.00 $1,002.00 $1,102.00 的值。当我尝试按以下方式排序时,
$1,002.00
$1,102.00
$26.70
$50.00
$52.00
$100.00
需要像这样的值,
$26.70
$50.00
$52.00
$100.00
$1,002.00
$1,102.00
尝试了这里提到的许多解决方案,但没有成功。
最佳答案
Tablesorter 允许您为此类内容定义“custom parsers ”。
// add parser through the tablesorter addParser method
$.tablesorter.addParser({
// set a unique id
id: 'thousands',
is: function(s) {
// return false so this parser is not auto detected
return false;
},
format: function(s) {
// format your data for normalization
return s.replace('$','').replace(/,/g,'');
},
// set type, either numeric or text
type: 'numeric'
});
$(function() {
$("table").tablesorter({
headers: {
6: {//zero-based column index
sorter:'thousands'
}
}
});
});
您可能需要调整格式功能,我尚未测试过。
关于jQuery tablesorter - 不对具有格式化货币值的列进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9027438/