我想对交换列表进行排序。它看起来是外币的价值。但是,这个国家有物有所值。转换值和排序,以显示实际值。
我无法按转换后的值排序。是那种出现的价值观。如何使用计算的值进行排序。但计算出的秘密值是什么?
<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
答案 0 :(得分:0)
我不确定你想要什么,但是我把this demo放在一起,它会根据计算的汇率对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) + ')');
希望我理解你想要的东西。