2012-07-06 48 views
1

我花了相當多的時間來扭轉周圍tablesorter得到它與價值工作,如:「R $ 3.400,95」 不用說,我失敗慘了。我曾嘗試添加headers: {2: {sorter:"currency"}}屬性,但它完全停止工作。 任何人有任何想法如何解決這個問題?Tablesorter貨幣清洗

的JavaScript:

$.tablesorter.addParser({ 
    // set a unique id 
    id: 'thousands', 
    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('$','').replace(/,/g,''); 
    }, 
    // set type, either numeric or text 
    type: 'numeric' 
}); 


$(function() { 
// call the tablesorter plugin 
$("#ver_saida").tablesorter({ 
    decimal: ",", 
    dateFormat: 'uk', 
    headers:{2:{sorter:'thousands'}} 
}); 

}); 

另一頭做工精細,但最後一個屬性使特定的頭停止工作。

下面是HTML表:

<table id="ver_saida" class="tablesorter"> 
    <thead> 
     <tr> 
      <th class="sorter-shortDate dateFormat-ddmmyyyy tablesorter-header">Data<span>n</span></th> 
      <th>Descrição<span>n</span></th> 
      <th>Valor<span>n</span></th> 
      <th>Situação<span style="margin-left:2em;">n</span></th> 
     </tr> 
    </thead> 
    <tr class="pago"> 
     <td class="datout">17/05/2012</td> 
     <td class="desout">atraso teste</td> 
     <td class="valout"> R$45,46</td> 
     <td class="situacao">pago</td> 
     <td class="delCel"><button class="deletar" href="financeiro_deletar.php?id=36">Deletar</button></td> 
    </tr> 
    <tr class="npago late"> 
     <td class="datout">13/06/2012</td> 
     <td class="desout">IPVA macerati</td> 
     <td class="valout"> R$5.565,62</td> 
     <td class="situacao">não pago</td> 
     <td class="delCel"><button class="deletar" href="financeiro_deletar.php?id=38">Deletar</button></td> 
    </tr> 
<table> 

我做了一個實驗:如果我參加了「R $」從細胞HTML時,它沒有問題讀,但事情是,我don1t知道如何讓它忽略「R $」並將它留在表格中(用於可讀性)。

回答

2

與修改的 '格式' 的方法:

format: function(s) { 
     // format your data for normalization 
     return parseFloat(s.replace(/[^0-9,]/g, '').replace(',', '.'), 10); 
    }, 
+0

偉大的工作,謝謝。 – 2012-07-06 20:20:40