jQuery TableSorter逗号数字解析器不起作用 [英] JQuery TableSorter Comma-Digit Parser not working

查看:102
本文介绍了jQuery TableSorter逗号数字解析器不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的问题,

我当前正在使用JQuery Table Sorter,并且在网上找到了Comma-Digit解析器.我遇到的问题是它似乎无法正常工作.

I am currently using the JQuery Table Sorter and I found a Comma-Digit parser on the web. The problem I am having is it doesn't seem to be working.

所以这是该列的排序方式:

So here is what the column is sorted as:

  1. 4,666
  2. 141,666
  3. 293
  4. 341,666
  5. 346
  6. 461,676

这应该排序为

  1. 293
  2. 346
  3. 4,666
  4. 141,666
  5. 341,666
  6. 461,676

我正在使用的解析器是这样的:

The parser I am using is this:

$( function() { 

    $.tablesorter.addParser({
        id: "fancyNumber",
        is: function(s) {
            return /^[0-9]?[0-9,\.]*$/.test(s);
        },
        format: function(s) {
            return $.tablesorter.formatFloat(s.replace(/,/g, ''));
        },
        type: "numeric"
    });
}); 

我只是不知道我做错了.我加载错了吗?解析器错了吗?我在这里需要真正的帮助,并且已经为这个问题苦苦挣扎了一段时间.

I just don't know I am doing wrong. Am I loading it wrong? Is the parser wrong? I need real help here and have been struggling with this problem for a while now.

编辑:由于我生成列的方式以及用户允许选择的列,我永远都不知道哪个标题位于或不位于哪个标题中.我已尝试使用class ="{sorter:'fancyNumber'}"命令,如下所示: http://tablesorter.com/docs/example-meta-parsers.html

Because of how I generate my columns and the columns allowed to be chosen by the user, I would never know which header is in and not. I have tried using the class="{sorter: 'fancyNumber'}" command as stated here: http://tablesorter.com/docs/example-meta-parsers.html

****看起来其中一列工作正常,但是此列仍然有问题.也许是因为它包含数字和逗号分隔的数字?

****It looks like one of the columns is working correctly, but this column is still having problems. maybe because it has digits and comma seperated digits?

推荐答案

针对遇到此问题的任何人.我必须将类添加到我的标题行.因此,对于我想进行排序的任何标题,我添加了此类:

For anyone that comes across this question. I had to add the class to my header row. So for any header that I wanted to fancy sort, I added this class:

<th class=\"{sorter: 'fancyNumber'}\">

默认情况下,这会打开分选器,使其工作正常.

This turned on the sorter by default which made it work nice.

让我意识到自己的错误的原因就是像这样打开调试器.

What made me realize my error in my ways was turning on the debugger like so.

$("#tblInfo").tablesorter({debug:true, widgets: ['zebra'], widgetZebra: { css: ['d0', 'd1']} });

这篇关于jQuery TableSorter逗号数字解析器不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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