jQuery tablesorter未正确排序数字 [英] jQuery tablesorter is not sorting number correctly
问题描述
我已经尝试了几天,以使jQuery tablesorter正确地对我的表列中的数字进行排序.
I've been trying for days now to get jQuery tablesorter correctly sort numbers in my table column.
我正在使用两个脚本的最新版本.
I am using the current latest versions of both scripts.
该表呈现良好,但是对数字进行排序无法正常工作.
The table is rendered fine, but sorting the numbers is not working correctly.
当我对数字列进行排序时,会得到以下结果:
When I sort a number column it gives me the following results:
8 7 4 32 31 3 等.
8 7 4 32 31 3 etc..
您期望的位置: 32 31 8 等等...
where you would expect: 32 31 8 etc...
我阅读了一些有关添加额外的javascript代码的评论,但找不到任何好的javascript示例.
I read some comments on adding extra javascript code but I can't find any good javascript examples.
我现在使用的jQuery如下:
The jQuery I'm using now is as follows:
$(document).ready(function()
{
$("#table1")
.tablesorter(
{
sortList: [[0,0]],
widthFixed: true,
widgets: ['zebra']
} )
}
);
这是我的HTML:
<table id="table1" class=tablesorter>
<thead>
<tr>
<th width=65>Name</th>
<th width=40>Count</th>
</tr>
</thead>
<tbody>
<tr><td>Name_1</td><td>32</td></tr>
<tr><td>Name_2</td><td>12</td></tr>
<tr><td>Name_3</td><td>11</td></tr>
<tr><td>name_4</td><td>14</td></tr>
<tr><td>Name_5</td><td>7</td></tr>
<tr><td>Name_6</td><td>3</td></tr>
<tr><td>Name_7</td><td>32</td></tr>
<tr><td>Name_8</td><td>31</td></tr>
<tr><td>Name_9</td><td>35</td></tr>
</tbody>
</table>
推荐答案
<th width=110 class=\"{sorter: 'digit'}\">Count</th>
这解决了问题. 告诉javascript将值作为数字来处理使排序工作正确无误. 仍然有点傻,脚本中没有将数字值检查为数字.但是我想这最终会有更高的目的.
This solved the problem. Telling the javascript to handle the value's as a digit made the sorting work correct. Still bit silly that number values are not checked in the script as being numbers. But i guess there is a higher purpose for that in the end.
感谢您的时间和帮助
/Fons
这篇关于jQuery tablesorter未正确排序数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!