使用jQuery表格排序器对表列进行排序 [英] Sorting Table Columns with jQuery Table Sorter
本文介绍了使用jQuery表格排序器对表列进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有办法使用表格分类器对列进行排序
因此我可以根据某些ID或任何内容自行排列列。
I was wondering if there's a way to sort columns with Table sorter
So that I could arrange the columns themselves according to some ID or anything.
所以这里举个例子,如果我想对表格进行排序,以便Apple列
首先,我该怎么做?
So here for instance, If I want to sort the table so that the Apple column
Would be first, how do I do that?
推荐答案
演示: http://jsfiddle.net/fKMqD/
Demo: http://jsfiddle.net/fKMqD/
代码:
var rows = $('tr');
rows.eq(0).find('td').sort(function(a, b){
return $.text([a]) > $.text([b]) ? 1: -1;
}).each(function(newIndex){
var originalIndex = $(this).index();
rows.each(function(){
var td = $(this).find('td');
if (originalIndex !== newIndex)
td.eq(originalIndex).insertAfter(td.eq(newIndex));
});
});
无需插件。
这篇关于使用jQuery表格排序器对表列进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文