Skip to content

Instantly share code, notes, and snippets.

@oelmekki
Created July 4, 2009 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oelmekki/140761 to your computer and use it in GitHub Desktop.
Save oelmekki/140761 to your computer and use it in GitHub Desktop.
/**
* 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+'&param='+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