【发布时间】:2015-03-31 19:55:59
【问题描述】:
对于此处的任何重复,我深表歉意,我已经尝试对此主题进行搜索,但没有成功。我有一个使用 jQuery TableSorter 排序的表,并且正在使用自定义解析器对 9 列中的 5 列进行排序。当通过表头文本触发时,自定义解析器运行良好,但我想通过表外的链接对表列进行排序。
对于那些不使用自定义解析器的列,我已经能够使用以下实现通过表外的链接对它们进行排序(请参阅http://tablesorter.com/docs/example-trigger-sort.html):
$(document).ready(function() {
$("table").tablesorter();
$("#trigger-link").click(function() {
// set sorting column and direction, this will sort on the first and third column the column index starts at zero
var sorting = [[0,0],[2,0]];
// sort on the first column
$("table").trigger("sorton",[sorting]);
// return false to stop default link action
return false;
});
});
现在我需要某种方式对我的列进行排序,这些列通过表外的链接使用自定义解析器。例如。我需要某种方式使用上面的代码来触发下面的代码(见http://tablesorter.com/docs/example-parsers.html):
// add parser through the tablesorter addParser method
$.tablesorter.addParser({
// set a unique id
id: 'grades',
is: function(s) {
// return false so this parser is not auto detected
return false;
},
format: function(s) {
// format your data for normalization
return s.toLowerCase().replace(/good/,2).replace(/medium/,1).replace(/bad/,0);
},
// set type, either numeric or text
type: 'numeric'
});
$(function() {
$("table").tablesorter({
headers: {
6: {
sorter:'grades'
}
}
});
});
任何想法或建议将不胜感激。
干杯,
杰克
【问题讨论】:
标签: jquery parsing sorting tablesorter