Tablesorter没有排序数百万

时间:2012-02-20 19:22:00

标签: sorting

我正在为我妻子的业务建立一个移动房地产网站,使用Tablesorter按价格排序。它适用于6位数字(包括$ s和逗号),例如$ 600,000然而,当遇到7位数时,它会失败,例如, $ 1,295,000。

在我的

    <script type="text/javascript" id="js">$(document).ready(function() {
$("table").tablesorter({
    // sort on the second column, order asc
    sortList: [[1,0]],
    headers: {
 1: { sorter: 'digit' } // column number, type
    }
});

});

<table cellspacing="2" class="tablesorter { 0: { sorter: false}, 1: {sorter: true} }">
            <thead>
        <tr>
            <th width="158" class="headerempty">Property</th>
            <th width="130" class="{'sorter':'currency'}">Sort by Price</th>
        </tr>
    </thead>
<tbody>
    <tr class="odd">
        <td><img src="../sales/29 Laurel Way/prepped_images/29lw-for_mobile.jpg" title="Tap for Details" alt="29 Laurel Way" width="150" height="100" border="0"></td>
        <td class="{'sorter':'currency'}">$329,000</td>
    </tr>
    <tr class="odd">
        <td><img src="../sales/Aetna Lane/al_for_Mobile.jpg" width="150" height="100"></td>
        <td class="{'sorter':'currency'}">$175,000</td>
    </tr>
    <tr class="odd">
        <td><img src="../sales/Atop Smith Hill/prepped/ash_mobile.jpg" width="150" height="100"></td>
        <td class="{'sorter':'currency'}">$1,295,000</td>
    </tr>
    <tr class="odd">
        <td><img src="../sales/Beech Hill/bh_mobile.jpg" width="150" height="100"></td>
        <td class="{'sorter':'currency'}">$595,000</td>
    </tr>
    <tr class="odd">
        <td class="{'sorter':'currency'}"><img src="../sales/Bluefield/b_mobile.jpg" width="150" height="100"></td>
        <td>$299,000</td>
    </tr>
</tbody>
    </table>

关于解决这个问题的任何想法?非常感谢,clpix

1 个答案:

答案 0 :(得分:1)

td class="{'sorter':'currency'}"这样的结构让我很害怕。你可能应该使用这个类在JS中定义类class sortable和init表,并在构造函数中定义排序参数:

$(".sortable").tablesorter({
// sort on the second column, order asc
sortList: [[1,0]],
headers: {
    1: { sorter: 'currency' } // column number, type
}
});
<table class='sortable'>
    <tr>
        <td>$1.000.000</td>
    </tr>
    ......
</table>

并查看分隔符.,

This code work很好。