重新排序表格列? [英] Re-order table columns?
本文介绍了重新排序表格列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人知道使用jQuery重新排序表列的方法吗?
Does anyone know a way to re-order table columns, using jQuery?
我的意思不是排序-我的意思是在表格中向左或向右动态移动整个列.
I don't mean sort - I mean dynamically move entire columns left or right in a table.
我知道出色的可拖动插件,但是我不需要让用户移动列,我需要一些可以以可配置方式进行重新排序的东西.
I'm aware of the excellent dragtable plugin, but I don't need something that allows the user to move columns, I need something that will do the re-ordering in a configurable way.
推荐答案
该想法是遍历表的所有行(tr)并交换所需的td.让我们交换第2列和第4列:
The idea is to walk over all rows (tr's) of the table and swap the desired td's. Let's swap column 2 and column 4:
$('table tr').each(function() {
var tr = $(this);
var td1 = tr.find('td:eq(1)'); // indices are zero-based here
var td2 = tr.find('td:eq(3)');
td1.detach().insertAfter(td2);
});
我希望这会有所帮助.
这篇关于重新排序表格列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文