javascript-jquery-tablesorter的问题:如果表头是多行的,点击排序好像就不正确了

来源:互联网 发布:淘宝刷手p图软件 编辑:程序博客网 时间:2024/04/30 05:18

表头里使用了colspan/rowspan后,就不灵了——有人在bbs.jquery.org.cn问了半年,也不见答案 

http://bbs.jquery.org.cn/read.php?tid-2318-fpage-11.html

看tablesorter自己的介绍,说是支持的:http://tablesorter.com/docs/  (下面红底部分)
Introduction
tablesorter is a jQuery plugin for turning a standard HTML table with THEAD and TBODY tags into a sortable table without page refreshes. tablesorter can successfully parse and sort many types of data including linked data in a cell. It has many useful features including:

Multi-column sorting
Parsers for sorting text, URIs, integers, currency, floats, IP addresses, dates (ISO, long and short formats), time. Add your own easily
Support for ROWSPAN and COLSPAN on TH elements
Support secondary "hidden" sorting (e.g., maintain alphabetical sort when sorting on other criteria)
Extensibility via widget system
Cross-browser: IE 6.0+, FF 2+, Safari 2.0+, Opera 9.0+
Small code size
  

 

仔细看看,好像是列号的判断出了问题:多行跨列时,这个插件还是按从上到下、从左到右地遍历表头里的th,按遇到的顺序设置列号


|c1|c2   |c3      |c4|
|  |--+--+--+--+--|  |
|  |c5|c6|c7|c8|c9|  |

以上面的表头为例,其实只有7列;c8对应的实际上是第5列,但是tablesorter以为它是第8列!

现在th有一个属性设置的机会:<th ... class="{sorter:'text'}">用于指示该列的排序比较模式(按文本还是数值还是日期。。。。来比较该列的内容),不知道能不能扩展为:<th ... class="{sorter:'text'; truecolumn:'5'}">来指示点击该列表头,实际上将按第5列的内容来排序。。。。。。。。

 

这样就需要改写jquery.tablesorter.js文件。

 

原创粉丝点击