开发者

jquery tablesorter sorting numbers incorrectly

开发者 https://www.devze.com 2023-01-03 09:34 出处:网络
My table has a column of numbers which ar开发者_如何学Pythone sorted incorrectly. Example numbers:

My table has a column of numbers which ar开发者_如何学Pythone sorted incorrectly.

Example numbers:
5.8
2.4
10.7
0.1
1.9

and basically my problem is 10.7 should be at the very end/very start depending on which way it was sorted. but it is showing up in the middle.


Try manually specifying the column parser. You can do this easily via metadata -- indicating the parser type in the class of the table header for the column in question. For example:

<th class="{sorter: 'floating'}">

Further reading:

  • Setting parsers with metadata
  • List of available parsers (Tablesorter's own documentation is weak on this. Of course you can also look at the source.)
  • Writing a custom parser


See Ken's answer, but note that 'floating' no longer exists in newer versions (and neither does 'integer'). You now need to use 'digit' instead.

ts.addParser({
  id: "digit",
  is: function (s, table) {
    var c = table.config;
    return $.tablesorter.isDigit(s, c);
  }, format: function (s) {
    return $.tablesorter.formatFloat(s);
  }, type: "numeric"
});
0

精彩评论

暂无评论...
验证码 换一张
取 消