在JQuery tablesorter中 - 如何根据排序顺序更改解析器

时间:2014-02-19 06:04:51

标签: jquery tablesorter

我在一个表上使用jQuery tablesorter,该表包含以逗号分隔的数字内容的列。我添加了一个自定义分析器,这解决了我对逗号格式化数字进行排序的问题。 我想要一个特殊情况,值'NA'总是在排序列的末尾,而不管排序顺序如何。我想到的一种方法是“调整”我正在使用的自定义分析器,比如下面代码的注释。

 $.tablesorter.addParser({
    id: 'number-sorter',
    is: function (s) {
        return false;
    },
    format: function (s) {
        return s.replace(/,/g, '');

        /* what I want here is -
        if(sortOrder == "asc")
            return s.replace(/,/g, '').replace('NA', Number.POSITIVE_INFINITY);
        else
            return s.replace(/,/g, '').replace('NA', Number.NEGATIVE_INFINITY);
        */

    },
    type: 'numeric'
});

我在确定排序顺序时遇到问题(我假设'sortOrder'的变量)。 或者还有其他方法吗?

1 个答案:

答案 0 :(得分:1)

实际上,从你看来你想要做的是在表格底部排序非数字。我有一个fork of tablesorter,其option named stringTo允许您设置字符串(非数字值)的排序位置:' max',' min&#39 ;,' top',' bottom',' none' (将字符串视为值为零的数字);所以在你的情况下,将值设置为' max'。

Check out the demo