jQuery tablesorter与多个div的排序列
我正在使用tablesorter,我想弄清楚如何排序与多个div的列。具体而言,我需要按照“prog-perc”div中的百分比对列进行排序。jQuery tablesorter与多个div的排序列
我一直在努力理解定制解析器/文本提取,所以如果可能的话,我正在寻找一个解释过程的答案。
HTML
<td class="transaction-table-hide">
<span class="status">&{enums.Select.ISCTDealStatus.values()[transaction?.status].name}</span>
<div class="prog-container">
<a href="#" class="form-info" rel="tooltip" title="">
<div class="progress rounded clearfix">
<div class="prog-quart fl"> </div>
<div class="prog-half fl"> </div>
<div class="prog-three-quart fl"> </div>
<div class="prog-perc">10%</div>
</div>
</a>
</div>
</td>
$.tablesorter.addParser({
id: 'currencyExtract',
is: function(s) {
return false;
},
format: function(s) {
return s
.replace(/ AUD/,0)
.replace(/ BHD/,0)
.replace(/ BBD/,0)
.replace(/ CAD/,0)
.replace(/ CNY/,0)
.replace(/ HRK/,0)
.replace(/ CZK/,0)
.replace(/ DKK/,0)
.replace(/ XCD/,0)
.replace(/ EGP/,0)
.replace(/ MTL/,0)
.replace(/ EUR/,0)
.replace(/ HKD/,0)
.replace(/ HUF/,0)
.replace(/ INR/,0)
.replace(/ ILS/,0)
.replace(/ JMD/,0)
.replace(/ JPY/,0)
.replace(/ JOD/,0)
.replace(/ KES/,0)
.replace(/ LVL/,0)
.replace(/ LTL/,0)
.replace(/ MUR/,0)
.replace(/ MXN/,0)
.replace(/ MAD/,0)
.replace(/ NZD/,0)
.replace(/ NOK/,0)
.replace(/ OMR/,0)
.replace(/ PLN/,0)
.replace(/ GBP/,0)
.replace(/ QAR/,0)
.replace(/ RON/,0)
.replace(/ RUB/,0)
.replace(/ SAR/,0)
.replace(/ SGD/,0)
.replace(/ ZAR/,0)
.replace(/ SEK/,0)
.replace(/ CHF/,0)
.replace(/ THB/,0)
.replace(/ THD/,0)
.replace(/ TRY/,0)
.replace(/ AED/,0)
.replace(/ USD/,0)
;
},
type: 'numeric'
});
$("#sorTable").tablesorter({
headers:{
1:{
sorter: 'shortDate'
},
3:{
sorter: 'currencyExtract'
},
4:{
sorter: 'currencyExtract'
},
5:{
sorter: false
}
},
textExtraction: function(node){
return node.childNodes[0].nodeValue;
},
/*textExtraction: function(node) {
var $n = $(node), $p = $n.find('.prog-perc');
return $p.length ? $p.text() : $n.text();
},*/
widgets: ['zebra'],
dateFormat: "uk"
}).tablesorterPager({container: $("#pager")});
使用textExtraction
选项来指定该分区(demo)
$('table').tablesorter({
// define a custom text extraction function
textExtraction: function(node) {
var $n = $(node), $p = $n.find('.prog-perc');
// extract data from markup and return it
return $p.length ? $p.text() : $n.text();
}
});
不要担心%
的符号的百分比解析器应检测到它。
非常感谢,非常感谢! – 2012-07-31 08:34:06
这工作对我来说,但我没有意识到,它杀了我的其他textExtraction,我已经添加了我的完整tablesorter脚本,你可以编辑你的答案,包括支持两者?谢谢 – 2012-08-03 08:29:57
也许一个更好的选择是使用我的fork [tablesorter](http://mottie.github.com/tablesorter/docs/example-option-text-extraction.html)。它允许您为列添加特定的textExtraction函数。 – Mottie 2012-08-03 17:23:10
请参阅我的答案为通用的排序方式: http://stackoverflow.com/a/12920117/1544054 – Aviko 2012-10-16 17:30:38