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.
So here for instance, If I want to sort the table so that the Apple column
Would be first, how do I do that?
Demo: http://jsfiddle.net/fKMqD/
Code:
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));
});
});
No plugins necessary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With