Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added minified version.

  • Loading branch information...
commit 3c9957ffafb2523b5ca0cc747dd95399df8d3157 1 parent 6b39775
Kyle Fox authored

Showing 1 changed file with 5 additions and 0 deletions. Show diff stats Hide diff stats

  1. +5 0 jquery.tablesort.min.js
5 jquery.tablesort.min.js
... ... @@ -0,0 +1,5 @@
  1 +$(function(){var $=window.jQuery;function sortValueForCell(th,td,sorter){if(th.data().sortBy){var sortBy=th.data().sortBy;return typeof sortBy==="function"?sortBy(th,td,sorter):sortBy}if(td.data().sortValue)return td.data().sortValue;else return td.text()}$.tablesort=function($table,settings){var self=this;this.$table=$table;this.settings=$.extend({},$.tablesort.defaults,settings);this.$table.find("thead th").bind("click.tablesort",function(){self.sort($(this))});this.index=null;this.$th=null;this.direction=
  2 +null};$.tablesort.prototype={sort:function(th,direction){var start=new Date,self=this,table=this.$table,rows=table.find("tbody tr"),aRow,bRow,aIndex,bIndex,cache=[];if(rows.length===0)return;self.$table.find("thead th").removeClass(self.settings.asc+" "+self.settings.desc);this.index=th.index();this.$th=th;if(direction!=="asc"&&direction!=="desc")this.direction=this.direction==="asc"?"desc":"asc";else this.direction=direction;direction=this.direction=="asc"?1:-1;self.$table.trigger("tablesort:start",
  3 +[self]);self.log("Sorting by "+this.index+" "+this.direction);rows.sort(function(a,b){aRow=$(a);bRow=$(b);aIndex=aRow.index();bIndex=bRow.index();if(cache[aIndex])a=cache[aIndex];else{a=sortValueForCell(th,self.cellToSort(a),self);cache[aIndex]=a}if(cache[bIndex])b=cache[bIndex];else{b=sortValueForCell(th,self.cellToSort(b),self);cache[bIndex]=b}if(a>b)return 1*direction;else if(a<b)return-1*direction;else return 0});rows.each(function(i,tr){table.append(tr)});th.addClass(self.settings[self.direction]);
  4 +self.log("Sort finished in "+((new Date).getTime()-start.getTime())+"ms");self.$table.trigger("tablesort:complete",[self])},cellToSort:function(row){return $($(row).find("td").get(this.index))},log:function(msg){if(($.tablesort.DEBUG||this.settings.debug)&&console&&console.log)console.log("[tablesort] "+msg)},destroy:function(){this.$table.find("thead th").unbind("click.tablesort");this.$table.data("tablesort",null);return null}};$.tablesort.DEBUG=false;$.tablesort.defaults={debug:$.tablesort.DEBUG,
  5 +asc:"sorted ascending",desc:"sorted descending"};$.fn.tablesort=function(settings){var table,sortable,previous;return this.each(function(){table=$(this);previous=table.data("tablesort");if(previous)previous.destroy();table.data("tablesort",new $.tablesort(table,settings))})}});

0 comments on commit 3c9957f

Please sign in to comment.
Something went wrong with that request. Please try again.