Created
July 4, 2009 22:55
-
-
Save oelmekki/140761 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* TableSorter | |
* @param: options (request,action,destination,prev,next,rows,method,head) | |
* @return void; | |
*/ | |
var TableSorter = new Class({ | |
Implements: [Options], | |
options:{ | |
request: '', action: '', destination: '', prev: '', next: '', rows: 50, method: 'get', head: '' | |
}, | |
initialize: function(options){ | |
this.responseText = ''; | |
this.orderBy = ''; | |
this.column = ''; | |
this.param = ''; | |
this.setOptions(options); | |
this.setDomElements(); | |
}, | |
send: function(column,param,start){ // send resort request | |
var destination = this.options.destination; | |
this.column = column; | |
this.param = param; | |
var _sorter_ = this; | |
displayAjaxLoader($(destination),1); | |
var xhr = new Request({ | |
url: _main_href_, | |
method: this.options.method, | |
onComplete: function(){ | |
$(destination).innerHTML=xhr.response.text; | |
displayAjaxLoader($(destination),0); | |
_sorter_.setDomElements(); | |
}.bind( this ) | |
}).send(this.options.request+'='+this.options.action+'&column='+column+'&start='+start+'&rows='+this.options.rows+'¶m='+param+'&orderBy='+this.orderBy); | |
}, | |
setDomElements: function(column,param){ // set dom events | |
var _sorter_ = this; | |
$(this.options.prev).addEvent('click',function(){ | |
_sorter_.send(_sorter_.column,_sorter_.param,(this.title*1)-50); | |
}) | |
$(this.options.next).addEvent('click',function(){ | |
_sorter_.send(_sorter_.column,_sorter_.param,(this.title*1)); | |
}) | |
var childrenArr = $(this.options.head).getChildren(); | |
var childrenLen = childrenArr.length; | |
for(var i=0;i<childrenLen;i++){ | |
if(childrenArr[i].id!=''){ | |
$(childrenArr[i]).addEvent('click',function(){ | |
_sorter_.orderBy=this.title; | |
_sorter_.send(_sorter_.column,_sorter_.param); | |
}) | |
} | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment