不要考虑 tablesorter 上的 R 符号
do not take into account R symbol on tablesorter
我有一个 html table,我正在尝试使用 tablesorter 进行排序(我相信我有最新版本)。问题是当我对某些列进行排序时,结果排序不正确。具体来说,我列中的每个数字前面都有一个 "R" 字符(南非兰特的简写),当我对列进行排序时,它只对第一个数字进行排序,而不是对所有数字进行排序。例如。 R100 在某种程度上排在 R70 之前。我的 html 看起来像这样:
<div class="table-responsive container-fluid">
<table id="BrokerTable" class="table table-bordered table-hover tablesorter">
<thead>
<tr>
<th class="col-md-2">Broker<span class="glyphicon glyphicon-chevron-down headimage"></span></th>
<th class="col-md-2">Base Transaction Fee<br> (per trade)<span class="glyphicon glyphicon-chevron-down headimage"></span></th>
<th class="col-md-2">Minimum Transaction Fee<br> (per trade)<span class="glyphicon glyphicon-chevron-down headimage"></span></th>
<th class="col-md-2">Monthly Management Fee<br> (exc. VAT)<span class="glyphicon glyphicon-chevron-down headimage"></span></th>
<th class="col-md-2">Allows limit orders<br> (required for placing orders outside of trading hours)<span class="glyphicon glyphicon-chevron-down headimage"></span></th>
<th class="col-md-2">Allows stop-loss orders<span class="glyphicon glyphicon-chevron-down headimage"></span></th>
</tr>
</thead>
<tbody>
<tr>
<td><p>28E Capital</p></td>
<td><p>0.7% : R0-R49,999<br>0.5% : R50,000-R499,999<br>0.4% : R500,000-R999,999<br>0.35% : R1,000,000+</p></td>
<td><p>R125</p></td>
<td><p>R40</p></td>
<td><p><b class="greenTick">✓</b></p></td>
<td><p><b class="greenTick">✓</b></p></td>
</tr>
<tr>
<td><p>ABSA</p></td>
<td><p>0.4%</p></td>
<td><p>R120</p></td>
<td><p>R67</p></td>
<td><p><b class="greenTick">✓</b></p></td>
<td><p><b class="redcross">✘</b></p></td>
</tr>
<tr>
<td><p>AfriFocus</p></td>
<td><p>0.5%</p></td>
<td><p>R125</p></td>
<td><p>R65</p></td>
<td><p><b class="greenTick">✓</b></p></td>
<td><p><b class="greenTick">✓</b></p></td>
</tr>
</tbody>
</table>
我的 tablesorter js 是:
<script>
$(document).ready(function() {
$("#BrokerTable").tablesorter( {sortList: [[1,0]]} );
}
);
</script>
如果有人知道如何进行这项工作,那就太好了。
杰克
Tablesorter API支持使用自定义方法提取文本进行排序。试试这个:
var removeLeadingR = function(node) {
var text = $(node).text();
return text[0] === 'R' : text.substring(1) : text;
}
$(document).ready(function() {
$("#BrokerTable").tablesorter( {sortList: [[1,0]], textExtraction: removeLeadingR } );
});
我认为实际问题是原来的表格排序器 (v2.0.5) 不执行字母数字排序。
我做了一个 fork of tablesorter 有很多改进。它确实执行字母数字排序。
我创建了 a demo from the HTML you provided,但是里面没有 R100 或 R70,所以我添加了它们...
$(function () {
$("#BrokerTable").tablesorter({
sortList: [[1,0]],
theme: 'blue'
});
});
我有一个 html table,我正在尝试使用 tablesorter 进行排序(我相信我有最新版本)。问题是当我对某些列进行排序时,结果排序不正确。具体来说,我列中的每个数字前面都有一个 "R" 字符(南非兰特的简写),当我对列进行排序时,它只对第一个数字进行排序,而不是对所有数字进行排序。例如。 R100 在某种程度上排在 R70 之前。我的 html 看起来像这样:
<div class="table-responsive container-fluid">
<table id="BrokerTable" class="table table-bordered table-hover tablesorter">
<thead>
<tr>
<th class="col-md-2">Broker<span class="glyphicon glyphicon-chevron-down headimage"></span></th>
<th class="col-md-2">Base Transaction Fee<br> (per trade)<span class="glyphicon glyphicon-chevron-down headimage"></span></th>
<th class="col-md-2">Minimum Transaction Fee<br> (per trade)<span class="glyphicon glyphicon-chevron-down headimage"></span></th>
<th class="col-md-2">Monthly Management Fee<br> (exc. VAT)<span class="glyphicon glyphicon-chevron-down headimage"></span></th>
<th class="col-md-2">Allows limit orders<br> (required for placing orders outside of trading hours)<span class="glyphicon glyphicon-chevron-down headimage"></span></th>
<th class="col-md-2">Allows stop-loss orders<span class="glyphicon glyphicon-chevron-down headimage"></span></th>
</tr>
</thead>
<tbody>
<tr>
<td><p>28E Capital</p></td>
<td><p>0.7% : R0-R49,999<br>0.5% : R50,000-R499,999<br>0.4% : R500,000-R999,999<br>0.35% : R1,000,000+</p></td>
<td><p>R125</p></td>
<td><p>R40</p></td>
<td><p><b class="greenTick">✓</b></p></td>
<td><p><b class="greenTick">✓</b></p></td>
</tr>
<tr>
<td><p>ABSA</p></td>
<td><p>0.4%</p></td>
<td><p>R120</p></td>
<td><p>R67</p></td>
<td><p><b class="greenTick">✓</b></p></td>
<td><p><b class="redcross">✘</b></p></td>
</tr>
<tr>
<td><p>AfriFocus</p></td>
<td><p>0.5%</p></td>
<td><p>R125</p></td>
<td><p>R65</p></td>
<td><p><b class="greenTick">✓</b></p></td>
<td><p><b class="greenTick">✓</b></p></td>
</tr>
</tbody>
</table>
我的 tablesorter js 是:
<script>
$(document).ready(function() {
$("#BrokerTable").tablesorter( {sortList: [[1,0]]} );
}
);
</script>
如果有人知道如何进行这项工作,那就太好了。
杰克
Tablesorter API支持使用自定义方法提取文本进行排序。试试这个:
var removeLeadingR = function(node) {
var text = $(node).text();
return text[0] === 'R' : text.substring(1) : text;
}
$(document).ready(function() {
$("#BrokerTable").tablesorter( {sortList: [[1,0]], textExtraction: removeLeadingR } );
});
我认为实际问题是原来的表格排序器 (v2.0.5) 不执行字母数字排序。
我做了一个 fork of tablesorter 有很多改进。它确实执行字母数字排序。
我创建了 a demo from the HTML you provided,但是里面没有 R100 或 R70,所以我添加了它们...
$(function () {
$("#BrokerTable").tablesorter({
sortList: [[1,0]],
theme: 'blue'
});
});