微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

jQuery tablesorter – 不使用格式化货币值排序列

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,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'
            }
        }
    });
});

你可能需要调整格式函数,我没有测试。

原文地址:https://www.jb51.cc/jquery/183437.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐