1

I want to sort the list of exchange. it looks the values ​​of foreign currencies. but, the country with the sort of value for money. transformed values ​​and the sort, to show the actual values​​.

I could not sort by a value converted. was the sort of values ​​that appear. How to sort with the values ​​calculated. But the secret values ​​calculated?

<script id="js">
    var dolar = 1.7849;
    var euro=2.3643;
    var yen=1;
    $(function() {
        $("table").tablesorter({ 
        theme: 'blue' 
        ,headers: {
                0: {
                    sorter: false
                },
                1: {
                    sorter: 'custom_sort_function'
                },
                2: {
                    sorter: false
                }
            }
        });
    });
</script>   

<table class="tablesorter">
    <thead>
        <tr>
            <th>ID</th>
            <th>Money</th>
            <th>Symbol</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>1</td><!-- exchenge value dolar * cellvalue -->
            <td>USD</td>
        </tr>
        <tr>
            <td>2</td>
            <td>1</td><!-- exchenge value euro * cellvalue -->
            <td>EUR</td>
        </tr>
        <tr>
            <td>3</td>
            <td>1YEN</td><!-- exchenge value yen * cellvalue -->
            <td></td>
            <td>TL</td>
        </tr>       
    </tbody>
</table>


Sample View:
Sort Money Field ASC
ID   Money   Symbol
--   ------- ----------
1    1YEN    YEN
2    1USD    USD
3    1EURO   EUR

Sort Money Field Desc
ID   Money   Symbol
--   ------- ----------
3    1EURO   EUR
2    1USD    USD
1    1YEN    YEN
4

1 回答 1

0

我不确定你想要什么,但我整理了这个演示,它将根据计算的汇率对 Money 列进行排序,但你不知道发生了什么,所以我在解析器中包含了一行来添加计算的值到表格单元格。

我稍微修改了 HTML:

<tbody>
    <tr>
        <td>1</td>
        <td data-value="usd">1</td><!-- exchenge value dolar * cellvalue -->
        <td>USD</td>
    </tr>
    <tr>
        <td>2</td>
        <td data-value="eur">1</td><!-- exchenge value euro * cellvalue -->
        <td>EUR</td>
    </tr>
    <tr>
        <td>3</td>
        <td data-value="yen">1</td><!-- exchenge value yen * cellvalue -->
        <td>YEN</td>
    </tr>       
</tbody>

然后使用此代码:

// add the exchange rate out here
var exchange = {
    usd : 1.7849,
    eur : 2.3643,
    yen : 1
};

// add parser through the tablesorter addParser method 
$.tablesorter.addParser({ 
  // set a unique id 
  id: 'exchange', 
  is: function(s) { 
    // return false so this parser is not auto detected 
    return false; 
  }, 
  format: function(s, table, cell, cellIndex) { 
    // format your data for normalization
    var $c = $(cell),
        cur = $c.attr('data-value'),
        val = $.tablesorter.formatFloat(s, table) * (cur ? exchange[cur] : 1);
    $c.append(' (' + val.toFixed(2) + ')');
    return val; 
  }, 
  // set type, either numeric or text 
  type: 'numeric' 
}); 

$('table').tablesorter({
    theme : 'blue',
    headers: {
        1: { sorter: "exchange" }
    }
});

如果您不想将计算值添加到单元格,则只需删除此行:

$c.append(' (' + val.toFixed(2) + ')');

希望,我明白你想要什么。

于 2012-12-23T05:09:23.357 回答