开发者

jQuery TableSorter Parser for Europeans

I have a table with numbers like that:开发者_JAVA百科 12000.34 which sort perfectly with default options.

I am italian, so I want that number to format like this: 12.000,34 (comma for decimals, dot for thousands).

I format like that but my tables stop sorting the right way.

So I build my own custom parser:

jQuery.tablesorter.addParser({
            id: "commaDigit",
            is: function(s) {
                return /^[0-9]?[0-9,\.]*$/.test(s);
            },
            format: function(s) {
                s = s.replace("%","")
                     .replace(/€/g, '')
                     .replace(/^\s+|\s+$/g,"")
                     .replace(/,/g, "")
                return jQuery.tablesorter.formatFloat(s);
            },
            type: "numeric"
        });     

It works with numbers like 12000,34 but not with 12.000,34 What do I have to do with that dot??

In addition, I'd like to sort also "integers" like "-1,23" "0,00" "+3,68"

How can I manipulate my "s" string for achieving that?


jQuery.tablesorter.addParser({
            id: "commaDigit",
            is: function(s) {
                return /^[0-9]?[0-9,\.]*$/.test(s);
            },
            format: function(s) {
                s = s.replace("%","")
                     .replace(/€/g, '')
                     .replace(/^\s+|\s+$/g,"")
                     .replace(",", "")
                     .replace(".", "")
                return jQuery.tablesorter.formatFloat(s);
            },
            type: "numeric"
        });     

This removes the . from the column value


for lager numbers you need to replace all '.' like this: and i want to only accept number from at least 1 digit long (so no empty lines) with at least a '.' or a ',' in it

jQuery.tablesorter.addParser({
        id: "commaDigit",
        is: function(s) {
            return /^[0-9]+([,\.][0-9]+)+$/.test(s);
        },
        format: function(s) {
            s = s.replace("%","")
                 .replace(/€/g, '')
                 .replace(/^\s+|\s+$/g,"")
                 .replace(",", "")
                 .replace(/\./g, "")
            return jQuery.tablesorter.formatFloat(s);
        },
        type: "numeric"
    });     
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜