Javascript addParser中具有动态格式函数的表排序器

Javascript addParser中具有动态格式函数的表排序器,javascript,jquery,tablesorter,Javascript,Jquery,Tablesorter,我正在对包含字符串的列使用TableSorter: $.tablesorter.addParser( { id: 'positions', is: function(s) { return false; }, format: function(s) { var abbr=s.replace(/[^a-zA-Z0-9]/g, '').slice(_sort

我正在对包含字符串的列使用TableSorter:

$.tablesorter.addParser(
    {
        id: 'positions',
        is: function(s) {
                return false;
            },
        format: function(s) {
                var abbr=s.replace(/[^a-zA-Z0-9]/g, '').slice(_sortpos);
                return abbr;
            },
        type: 'numeric'
    }
);
format函数应返回一个依赖于全局_sortpos变量的值。此值会动态更改。该行:

var abbr=s.replace(/[^a-zA-Z0-9]/g, '').slice(_sortpos);
去除所有非数字和非字母,然后删除一定数量的初始字符。目的是按照第_sortpos-th个字符进行排序

似乎发生的情况是,当解析器添加到表分类器时,format函数只对每个字符串解析一次。但是,出于我的目的,每次排序时都必须重新运行format函数

到目前为止,我已经尝试在每次排序时添加解析器。但这并不奏效。我还试图通过重新运行初始化来重新初始化tablesorter

$(".tablesorter").tablesorter(
    {
        sortReset: true,
        headers: {
            1: {
                sorter: 'positions'
            }
        }
    }   
); 
但是没有用


我能做什么?还有:是否有一个比较器函数可以用来潜入全局参数?然后我可以在解析器中格式化字符串,然后在比较器中动态使用slice()函数中的_sortpos。

我自己找到了答案:

$(document).ready(function() {  
    $(".tablesorter").tablesorter(
        {
            textSorter: function(a, b, table, column){                  
                if (column==1)
                {
                    var c=parseInt(a.replace(/[^a-zA-Z0-9]/g, '').slice(_sortpos));
                    var d=parseInt(b.replace(/[^a-zA-Z0-9]/g, '').slice(_sortpos));                 
                    return ((c < d) ? -1 : ((c > d) ? 1 : 0));
                }
                return a.localeCompare(b);              
            }           
        }
    );  
});
$(文档).ready(函数(){
$(“.tablesorter”).tablesorter(
{
textSorter:函数(a、b、表、列){
如果(列==1)
{
变量c=parseInt(a.替换(/[^a-zA-Z0-9]/g')。切片(_-sortpos));
变量d=parseInt(b.替换(/[^a-zA-Z0-9]/g')。切片(_-sortpos));
收益率((cd)-1:0));
}
返回a.localeCompare(b);
}           
}
);  
});

它不使用解析器,只使用自定义排序器对列==1进行排序。

因为我没有得到答案,但是我的答案,我很快就会接受。我仍然不确定我所做的是故意的还是黑客行为。