2014-10-08 49 views
1

我有很多表在我的网站上使用tablesorter,我正在寻找一种方法来排序“sorter:'digit'具有特定类名的列:”class =“note”。Tablesorter和自动分拣机数字?

我知道的一个头要做到这一点:

$(".tablesorter").tablesorter({ 
headers: { 
    0: { sorter: 'digit' } // column number, type 
} }); 

但有一个通用的方法来做到这一点是这样的HTML:

<th class="{sorter: 'digit'}">Note</th>

或与类名<th class="note">Note</th>在这样的JavaScript的某处

$(".tablesorter .note").tablesorter() ... 

因为我的专栏“注意”有时是第三列,有时第五等

我问这个,因为没有指定的“数字”命令,的tablesorter不知道如何分类编号...这里是un jsfiddle来展示我的意思:http://jsfiddle.net/2cmuy39L/

谢谢。

+0

您是否阅读过http://tablesorter.com/docs/#Demo? – bodi0 2014-10-08 13:50:43

回答

0

如果您使用我的fork of tablesorter,你可以做到这一点,至少两种不同的方式:

  1. 添加sorter-digit类名头

    <th class="note sorter-digit">Note</th> 
    
  2. 在使用一个类名headers option(新增于v2.17.0) - here is a demo

    headers : { 
        '.note' : { sorter: 'digit' } 
    } 
    
+0

谢谢!它不适合我,因为我在这个网站上使用tablesorter http://tablesorter.com/docs/,你从这个网站http://mottie.github.io/tablesorter/docs/使用,但你的是最后一个版本和说明我的。但它更重^^我的17ko,你的31ko ^^ – Jon 2014-10-08 17:50:08