tablesorter用逗号分隔数字

Har*_*thy 3 jquery tablesorter

我在使用tablesorter插件时遇到问题,例如:9,789,000.00等货币.

有谁知道这方面的工作?

请不要向我推荐其他图书馆.

Jac*_*cta 11

Tablesorter允许您为此类事件定义"自定义解析器".

// 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'
            }
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

您可能需要调整格式功能.

也试着在页面上搜索,这个主题已经被讨论了很多次,就像这里一样