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
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);
});
I hope this helps.