排除使用jQuery tablesorter对列进行排序 [英] Exclude a column from being sorted using jQuery tablesorter
本文介绍了排除使用jQuery tablesorter对列进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一种方法,以排除使用jQuery的tablesorter插件对单个列进行排序的方法.具体来说,我有一个相当大的表,并且希望将行号"列保持固定,以便在排序后可以轻松查看特定行在表中的位置.
I am looking for a way to exclude a single column from being sorted using jQuery's tablesorter plugin. Specifically, I have a fairly large table and would like to keep a "row number" column fixed so that it is easy to see what position in the table a particular row is, after sorting.
例如:
# name
-----------
1 papaya
2 apple
3 strawberry
4 banana
在名称"列上排序时,结果应为:
When sorted on the name column, should result in:
# name
-----------
1 apple
2 banana
3 papaya
4 strawberry
谢谢.
推荐答案
以下是您可以使用的小部件,它将完成您想要的内容:
Here is a widget you can use that will accomplish what you are looking for:
$(function() {
// add new widget called indexFirstColumn
$.tablesorter.addWidget({
// give the widget a id
id: "indexFirstColumn",
// format is called when the on init and when a sorting has finished
format: function(table) {
// loop all tr elements and set the value for the first column
for(var i=0; i < table.tBodies[0].rows.length; i++) {
$("tbody tr:eq(" + i + ") td:first",table).html(i+1);
}
}
});
$("table").tablesorter({
widgets: ['zebra','indexFirstColumn']
});
});
这篇关于排除使用jQuery tablesorter对列进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文