开发者

tablesorter works on all except one

开发者 https://www.devze.com 2023-01-31 01:49 出处:网络
I have a tablesorter that works on all except one column. See http://www.dbno.us/finance/beta/ol开发者_运维百科d.php?index=sp100

I have a tablesorter that works on all except one column. See http://www.dbno.us/finance/beta/ol开发者_运维百科d.php?index=sp100

When you click on P/E, it sorts incorrectly. On ascending order, it will put 223.68 ahead of 23.30. On descending order, it will put 9.22 ahead of 86.85.


P/E is being sorted alphabetically rather than numerically, the presence of "N/A" values is probably making tablesorter think that the column contains strings rather than numbers.

You want to use $.tablesorter.addParser() to add a custom parser for that column and then something like this to bind the parser to that column:

$("#stocktable").tablesorter({
    sortList: [[4,0],[6,1]],
    headers:  { 4: { sorter: 'yourCustomParser' } }
});

Where yourCustomParser is the parser you set up with .addParser(). Your custom parser will need to convert "N/A" to something numeric for the comparison. The tablesorter documentation has examples of custom parsers.

0

精彩评论

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