you are in: codestackercodes [RSS] → tag: table [RSS]

simple jquery table sort Delicious Email

requires jquery.sortElements.js (https://github.com/jamespadolsey/jQuery-Plugins/blob/master/sortElements/jquery.sortElements.js)

via http://stackoverflow.com/questions/3160277/jquery-table-sort

show/hide lines
   1  var table = $('table');
   2  
   3  $('th').wrapInner('<span title="Sort this column"/>').each(function(){
   4       var th = $(this), thIndex = th.index(), inverse = false;
   5       th.click(function(){
   6           table.find('td').filter(function(){
   7               return $(this).index() === thIndex;
   8           }).sortElements(function(a, b){
   9               return $.text([a]) > $.text([b]) ?
  10                   inverse ? -1 : 1
  11                   : inverse ? 1 : -1;
  12           }, function(){
  13  			return this.parentNode; 
  14           });
  15           inverse = !inverse;
  16       });
  17  });
created by leozera — 01 July 2011 — get a short url — tags: jquery table embed