jQuery表排序器';s自定义解析器 $(文档).ready(函数(){ jQuery.tablesorter.addParser({ id:“commaDigit”, is:功能{ 返回false; }, 格式:函数{ var=s.replace(“%”,“”) .替换(/€/g,“”) .替换(/^\s+|\s+$/g,“”) .替换(“,”,“”) .替换(“.”,”); 控制台日志(s+“->”+已剥离); 返回jQuery.tablesorter.formatFloat(剥离); }, 类型:“数字” }); $(“#repStatiOttica”).tablesorter({widgets:['zebra']}); });

jQuery表排序器';s自定义解析器 $(文档).ready(函数(){ jQuery.tablesorter.addParser({ id:“commaDigit”, is:功能{ 返回false; }, 格式:函数{ var=s.replace(“%”,“”) .替换(/€/g,“”) .替换(/^\s+|\s+$/g,“”) .替换(“,”,“”) .替换(“.”,”); 控制台日志(s+“->”+已剥离); 返回jQuery.tablesorter.formatFloat(剥离); }, 类型:“数字” }); $(“#repStatiOttica”).tablesorter({widgets:['zebra']}); });,jquery,tablesorter,Jquery,Tablesorter,我的一些标记: <script type="text/javascript"> $(document).ready(function() { jQuery.tablesorter.addParser({ id: "commaDigit", is: function(s) { return false; }, format: func

我的一些标记:

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

        jQuery.tablesorter.addParser({
            id: "commaDigit",
            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>
。。。
斯塔托
奥迪尼
奥尔迪尼%
...
文本和整数(第一列和第二列)排序正确

我尝试了这个解析器,旨在解析一系列数字,如下所示:

“23,19%”;"6,89%" ; “0,50%。”

“6.240,44欧元”;"€ 15.000,25" ; “100,00欧元”

你能帮我使解析器适应我的情况吗


请仅用测试过的解决方案回答:)

好吧,实际上你做的每件事都很好,唯一的一件事,表排序器必须获得
int
值。所以在解析值时,应该使用
parseInt
函数来表示实际的整数值


返回parseInt(剥离)

不确定原因,但分拣机的标记样式分配不起作用。使用“headers”tablesorter配置属性解决问题。

您需要使用jquery元数据插件才能使解析器元数据正常工作。

回答完全错误,解析器不工作:在“is:”函数中“return false”=>从不工作/触发;“return true”=>始终激发未请求列的事件;排序对欧元值不起作用!为了回答您的问题,
{sorter:'text'}
仅在包含元数据插件时有效。
...
<thead>
    <tr>
        <th class="{sorter: 'text'}"><b>Stato</b></th>
        <th><b>Ordini</b></th>
                <th class="{sorter: 'commaDigit'}"><b>Ordini %</b></th>
...