javascript - Tablesorter货币清洁

标签 javascript jquery html-table tablesorter

我花了相当多的时间来调整 arround tablesorter 以使其与值一起工作,例如:“R$ 3.400,95” 不用说,我惨败了。我确实尝试添加一个 headers: {2: {sorter:"currency"}} property ,但它完全停止工作了。 有人知道如何解决这个问题吗?

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'}}
});

});

其他 header 工作正常,但最后一个属性使该特定 header 停止工作。

这是 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>

我做了一个实验:如果我从单元格 html 中取出“R$”,它读取没有问题,但问题是,我不知道如何让它忽略“R$”并且仍然将其留在表格中(为了便于阅读)。

最佳答案

修改“格式化”方法:

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

关于javascript - Tablesorter货币清洁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11356444/

相关文章:

javascript - CSS 在一列中显示帖子网格,就像我添加的图像一样

javascript - openlayer 3 捕获移动结束/缩放结束事件

javascript - 仅覆盖箭头键滚动事件

javascript - 如何显示选定的日志级别?

jQuery ui 可排序表格行刷新里面的数字位置

javascript - React JSX 中的自定义 HTML 元素标记

javascript - 在 100 个元素中的每个循环中使用 5 个元素

javascript - video.js 使用 jQuery 动态改变颜色

css - 具有固定行高文本溢出省略号垂直对齐的响应式 html/css 表

r - 使用 expss 包调整列宽