I have a very simple HTML table with 4 columns:
Facility Name, Phone #, City, Specialty
I want the user to be able to sort by Faci
My vote! jquery.sortElements.js and simple jquery
Very simple, very easy, thanks nandhp...
$('th').live('click', function(){
var th = $(this), thIndex = th.index(), var table = $(this).parent().parent();
switch($(this).attr('inverse')){
case 'false': inverse = true; break;
case 'true:': inverse = false; break;
default: inverse = false; break;
}
th.attr('inverse',inverse)
table.find('td').filter(function(){
return $(this).index() === thIndex;
}).sortElements(function(a, b){
return $.text([a]) > $.text([b]) ?
inverse ? -1 : 1
: inverse ? 1 : -1;
}, function(){
// parentNode is the element we want to move
return this.parentNode;
});
inverse = !inverse;
});
Dei uma melhorada do código
One cod better!
Function for All tables in all Th in all time... Look it!
DEMO