开发者

Problem with jQuery TableSorter's custom parser

<script type="text/javascript">
    $(document).ready(function() {

        jQuery.tablesorter.addParser({
            id: "commaDig开发者_Python百科it",
            is: function(s) {
                return false;
            },
            format: function(s) {
                var stripped = s.replace("%","")
                     .replace(/€/g, '')
                     .replace(/^\s+|\s+$/g,"")
                     .replace(",", "")
                     .replace(".", "");
                console.log(s + " -> " + stripped);
                return jQuery.tablesorter.formatFloat(stripped);
            },
            type: "numeric"
        });         

        $("#repStatiOttica").tablesorter({widgets: ['zebra']});

    });
</script>

Some of my markup:

...
<thead>
    <tr>
        <th class="{sorter: 'text'}"><b>Stato</b></th>
        <th><b>Ordini</b></th>
                <th class="{sorter: 'commaDigit'}"><b>Ordini %</b></th>
...

Text and integers (first and second column) sort correctly.

I tried this parser aiming to parse series of numbers like that:

"23,19%" ; "6,89%" ; "0,50%"

or

"€ 6.240,44" ; "€ 15.000,25" ; "€ 100,00"

Can you help me adapt my parser to my case?

Please answer only with tested solutions :)


Not sure why, but markup-style assignment of the sorters does not work. Solved using "headers" tablesorter config property.


You need to have the jquery metadata plugin for parser metadata to work correctly.


Well, actualy you doing everything good, only thing, that TableSorter have to get int values. So when parse values, you should use parseInt function for actual integer value.

return parseInt(stripped);

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜