JQuery tablesorter自定义解析器到所有标头? [英] JQuery tablesorter custom parser to all headers?

查看:60
本文介绍了JQuery tablesorter自定义解析器到所有标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个tablesorter表,我需要为每个标头使用自定义解析器。我想知道是否有一种简单的方法可以做到这一点,例如:

I'm currently working with a tablesorter table in which I need to use a custom parser for each header. I'd like to know if there's an easy way to do this, such as:

table.tablesorter({ 
        headers: { 
            0-20: { 
                sorter:'CareerLast' 
            }, 

        } 
    }); 

我知道上面的代码不起作用,但我只是想知道是否还有更多应用自定义解析器的可读方式,除了通过索引手动将其放在每列上。

I know that the above code doesn't work, but I'm just wondering if there's a more readable way of applying the custom parser, other than manually placing it on each column by index.

推荐答案

嗯,我认为你有三种选择:

Well, I think you have three choices:


  1. 在初始化选项中定义每个标题,0到20。

  1. Define each header, 0 through 20 in the initialization options.

header : {
    0 : { sorter : 'CareerLast' },
    1 : { sorter : 'CareerLast' },
    2 : { sorter : 'CareerLast' },
    // etc
    20 : { sorter : 'CareerLast' }
}


  • 使用元数据插件并在标题类中添加分类器定义:

  • Use the meta data plugin and add the sorter definition in the header class:

    // untested, but I think this will work
    $('table').find('thead th').addClass("{sorter:'CareerLast'}");
    $('table').tablesorter();
    


  • 试试我的分叉版本的tablesorter ,只需将分拣机添加为类名

  • Try out my forked version of tablesorter and just add the sorter as a class name

    $('table').find('thead th').addClass('sorter-CareerLast');
    $('table').tablesorter();
    


  • 这篇关于JQuery tablesorter自定义解析器到所有标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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