JQUERY Tablesorter无法正确对数字列进行排序

蚜虫

我在排序包含浮点数和整数的列时遇到问题:

例子

当前列的排序方式如下:

4697.2
403.95
399.38
317.94
316.44
3138.7
308.28
262.75
1839.5
179.94
159.97
145.99
103.95
94.95
90.24
819.9

我想按值对列进行排序,因为目前看来按字符长度对数字进行排序-可能吗?

这是我的javascript:

<script>

$(function(){
    $('table').tablesorter({
        widgets        : ['zebra', 'columns', 'stickyHeaders'],
        usNumberFormat : false,
        numberSorter: function (a, b, direction) {
    if (a >= 0 && b >= 0) { return direction ? a - b : b - a; }
    if (a >= 0) { return -1; }
    if (b >= 0) { return 1; }
    return direction ? b - a : a - b;
}
    });
});

</script>

有人可以让我知道我需要做些什么来纠正这个问题吗?谢谢

多纳尔

该修复程序由@ fuchs777提出。usNumberFormat设置被设置为false。这意味着表排序程序将值当作德国数字格式来对待,例如1.234.567,89使用德国数字格式时,千位用句点(句号)表示,而不用逗号表示。

修复程序正在设置 usNumberFormat : true

例如:

$(function(){
    $('table').tablesorter({
        widgets        : ['zebra', 'columns', 'stickyHeaders'],
        usNumberFormat : true,
        numberSorter: function (a, b, direction) {
        if (a >= 0 && b >= 0) { return direction ? a - b : b - a; }
        if (a >= 0) { return -1; }
        if (b >= 0) { return 1; }
        return direction ? b - a : a - b;
    }
    });
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章