Plugin - comma decimals

泪湿孤枕 提交于 2019-12-01 09:40:31
Stefan T

Ok, I think I solved it. My table has currency so I edited the 'currency' parser but you could basically do it with any other. Currency parser looks like this in the end:

ts.addParser({
    id: "currency",
    is: function(s) {
        return /^[£$€?.]/.test(s);
    },
    format: function(s) {
        s=s.replace('.', '');
        return $.tablesorter.formatFloat(s.replace(new RegExp(/[^0-9.]/g),""));
    },
    type: "numeric"
});

(by the way, how do you turn on synthax highlight here on stackoverflow?)

'1.234,56'​.replace('.', '').replace(',', '.') // '1234.56'
$.tablesorter.addParser({ 
        // set a unique id 
        id: 'pesos', 
        is: function(s) { 
            // return false so this parser is not auto detected 
            return false; 
        }, 
        format: function(s) { 
            // format your data for normalization
            return s.replace(/' '/g,'').replace(/\./g, ''); 
        }, 
        // set type, either numeric or text 
        type: 'numeric' 
    });
    $("#menuh").sticky({topSpacing:0});
    $("#myTable").tablesorter();
    $("#myTableBienes").tablesorter({ 
            headers: { 
                5: { 
                    sorter:'pesos' 
                } 
            } 
        });


});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!