2011-09-12 59 views
0
<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> 

我的一些標記:問題與jQuery的tablesorter的自定義分析器

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

文字和整數(第一和第二列)排序正確。

我想這個目標解析器解析這樣的一系列數字:

「23,19%」; 「6,89%」; 「0.50%」

「6.240.44」;「 「15.000,25歐元」; 「€100,00」

你能幫我調整一下我的解析器嗎?

請只用測試的解決方案嘛:)回答

回答

0

不知道爲什麼,但分揀機的標記式的分配無法正常工作。使用「標題」tablesorter配置屬性解決。

+0

要回答你的問題,'{sorter:'text'}'只有包含元數據插件纔有效。 – Mottie

-1

,actualy你做什麼都好,唯一的事情,是的tablesorter必須得到int值。因此,在解析值時,應該使用parseInt函數來計算實際整數值。

return parseInt(stripped);

+0

完全錯誤的答案,解析器無法正常工作:在「is:」函數中「return false」=>從不工作/觸發; 「return true」=>總是觸發,未請求列的事件;排序不適合€值! –

0

您需要有jQuery元數據插件才能使分析器元數據正常工作。