我使用的是jQuery表of插件,我有一个列,其中包含月份和年份的名称,如下所示
April, 1975
January, 2001我想把这个列分类,就像它是一个日期列。据我所知,可以使用其他“隐藏”值对列进行排序,但我似乎找不到该特性的文档。有什么帮助吗?
更新
tablesorter的这个分叉http://mottie.github.com/tablesorter/docs/index.html正是我所需要的;它能够在属性中存储要排序的值,效果非常好。
发布于 2012-03-11 13:48:22
我有一个制表器叉,它允许您编写一个解析器,该解析器可以从表单元格中生成提取数据属性并分配特定的每个列的textExtraction。
$(function(){
$.tablesorter.addParser({
// set a unique id
id: 'myParser',
is: function(s) {
// return false so this parser is not auto detected
return false;
},
format: function(s, table, cell, cellIndex) {
// get data attributes from $(cell).attr('data-something');
// check specific column using cellIndex
return $(cell).attr('data-something');
},
// set type, either numeric or text
type: 'text'
});
$('table').tablesorter({
headers : {
0 : { sorter: 'myParser' }
}
});
});发布于 2013-03-07 06:55:45
只使用textExtraction函数。在TDs上设置数据排序值。默认为正常文本,如果它不存在。
$(".sort-table").tablesorter({
textExtraction: function(node) {
var attr = $(node).attr('data-sort-value');
if (typeof attr !== 'undefined' && attr !== false) {
return attr;
}
return $(node).text();
}
}); 发布于 2017-02-09 15:59:44
这现在是tablesorter的一个标准特性,尽管由于某种原因它是没有文档化的。如果打开文件https://github.com/christianbach/tablesorter/blob/master/jquery.tablesorter.js并查看# 307行,您将看到它支持“数据排序值”属性。
用法:
<td data-sort-value="42">Answer to the question</td>https://stackoverflow.com/questions/9550354
复制相似问题