2012-10-26 97 views
0

有七列,我想正确排序有他们,的jQuery的tablesorter不正确排序,我不知道我怎么

第一列数字,但是它并没有命令他们,我想的方式他们被下令:

Example: 
5016 
502 
5020 
5023 

,我想它排序是这样的:

Example: 
502 
5016 
5020 
5023 

现在的第2列有数字和字母 前的组合充足就像以上,但在每个号码 之前,前面的字母,我想那种用数字,然后通过信件

Example: 
441 
B441 
821 
822 
823 
C823 

甚至像这将是确定

Example: 
441 
821 
822 
823 
B441 
C823 

最后, 第3列是更复杂的它有一个图像之前的词语例子是:  比利琼斯  安娜沃尔特斯   Bob Smith的  汤姆·亨德森

所有我想它由(名称)字母订购...

Example: 
<img src="img_tr122.png">&nbsp;Anna Walters 
<img src="img_tr122.png">&nbsp;Billy Jones 
<img src="img_tr122.png">&nbsp;Bob Smith 
<img src="img_tr122.png">&nbsp;Tom Henderson 

这里是我在JavaScript到目前为止,但我不知道如何得到的一切工作..

<script type="text/javascript"> 
$(document).ready(function() { 
$.tablesorter.defaults.widgets = ['zebra']; 
    $("table").tablesorter({ 
     // pass the headers argument and assing a object 
     headers: { 
      // assign the third column (we start counting zero) 
      2: { 
       // disable sort because I don't know how to sort it correctly. 
       sorter: false 
      }, 
      6: { 
       // disable sort for this (last) column because it is a menu only. 
       sorter: false 
      } 
     } 
    }); 
}); 
</script> 

请帮助....

谢谢!!!!

回答

2

原始tablesorter(v2.0.5)不会执行字母数字排序。但是你可以使用我的fork of tablesorter使用该代码的数据进行排序:

$('table').tablesorter({ 

    // Add a theme 
    theme : 'blue', 

    // extract text from the table 
    textExtraction: { 
     2: function(node) { 
      // move swap first and last name 
      return $.trim($(node).text() || '').replace(/(\w+)\s(\w+)/g,'$2 $1'); 
     } 
    }, 

    // include zebra and any other widgets: 
    widgets: ['zebra', 'columns'] 

}); 

我不知道你怎么想的最后一列进行排序。 textExtraction选项包含的代码先按姓氏排序最后一列。如果你想按名字排序,那么只需删除整个选项。

这里是a demo的代码在行动。

+0

这是伟大的!非常感谢你的例子! – compcobalt

0

您可以使用http://tablesorter.openwerk.de/它具有您需要的功能,它具有区域设置支持,UI主题支持,支持德语日期格式和小数点。