Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Version 0.0.1

  • Loading branch information...
commit fb47a6954bcf8a54d5beb8b84765a4904d6fc39b 1 parent 3c9957f
@kylefox authored
Showing with 11 additions and 0 deletions.
  1. +6 −0 jquery.tablesort.js
  2. +5 −0 jquery.tablesort.min.js
View
6 jquery.tablesort.js
@@ -1,3 +1,9 @@
+/*
+ A simple, lightweight jQuery plugin for creating sortable tables.
+ https://github.com/kylefox/jquery-tablesort
+ Version 0.0.1
+*/
+
$(function() {
var $ = window.jQuery;
View
5 jquery.tablesort.min.js
@@ -1,3 +1,8 @@
+/*
+ A simple, lightweight jQuery plugin for creating sortable tables.
+ https://github.com/kylefox/jquery-tablesort
+ Version 0.0.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=
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",
[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]);

0 comments on commit fb47a69

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