jQuery tablesorter-不对具有格式化货币值的列进行排序 [英] jQuery tablesorter - Not sorting column with formatted currency value

查看:46
本文介绍了jQuery tablesorter-不对具有格式化货币值的列进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQuery 1.7.1& tablesorter插件-我有一个带有一千个分隔符的货币列,其值像$ 52.00 $ 26.70 $ 100.00 $ 50.00 $ 1,002.00 $ 1,102.00.当我尝试通过以下方式进行排序时,

jQuery 1.7.1 & tablesorter plugin - I have a currency column with thousand separators and values like $52.00 $26.70 $100.00 $50.00 $1,002.00 $1,102.00. When I try to sort getting sorted in the following way,

   $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

尝试了此处提到的许多解决方案,但没有成功.

Tried many solutions mentioned here, but no success.

推荐答案

Tablesorter允许您定义"自定义解析器"表示这样的事情.

Tablesorter allows you to define "custom parsers" for things like this.

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

您可能需要调整格式功能,而我尚未测试过.

You may have to tweak the format function, which I've not tested.

这篇关于jQuery tablesorter-不对具有格式化货币值的列进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆