// jsTables - relies on jquery // Written By Marc Castles Small Dog Design image_path = "/puppy/images/"; preload_images(image_path + "table_header_over.jpg",image_path + "arrow_ASC.png",image_path + "arrow_DESC.png"); var jsTables = new Array(); $(function() { //if js tables exist in page make them for(var i=0; i'; } else { html += ''; } if(this.sortby == this.cols[i].field) { selectedNum = i; } if(this.cols[i].label) { if(this.cols[i].sort == true) { html += ''+this.cols[i].label+""; } else { html += this.cols[i].label; } } if(this.cols[i].headDraw) { html += this.cols[i].headDraw($(this)); } html += ''; } html += ""; $("#"+this.div).append(html); if(selectedNum != null) { btn = $("#"+this.div+" tr th:eq("+selectedNum+") a"); $(btn).parent().css("background","url("+image_path+"table_header_over.jpg)"); $(btn).css("background","url("+image_path+"arrow_"+this.sortdir+".png) no-repeat 3px center"); $(btn).css("padding-left","20px"); this.sorted = btn; } if(this.loadFunc) { this.loadFunc(); } if ( req ) req.abort(); req = $.post(this.xml,this.postvars() , function(xml) { $("#"+self.div+" table tr:has(td)").remove(); //remove all previous rows self.draw(xml); if(self.completeFunc) { self.completeFunc(); } }); } this.draw = function(xml) { var total = $(xml).find("data").attr("total"); $(xml).find('row').each(function(i){ var rows = ''; var leftshown = false; //to apply left css for(var i=0; i'; } else if(i == (self.cols.length-1)) { rows += ''; } else { rows += (css == "" ? '' : ''); } if(show) { leftshown = true; } if(self.cols[i].cellDraw) { rows += self.cols[i].cellDraw($(this),total); } else if(self.cols[i].field && $(this).attr(self.cols[i].field) != undefined) { rows += $(this).attr(escape(self.cols[i].field)); // Display code is here } rows += ''; } rows += ''; $("#"+self.div+" table").append(rows); }); $("#"+this.div+" tr:even").attr('className','row'); $("#"+this.div+" tr:odd").attr('className','row1'); if(this.limit != "") { var pages = Math.ceil(total/this.limit); if(pages > 1) { start = 0; end = pages; html = ''; if(this.page > 0) { html += 'previous'; } for(var i=start; i'; } if(this.page < (end-1)) { html += 'next'; } html += '
'; if($("#"+self.div).children().size() == 1) { $("#"+self.div).append('
'+html+'
'); } else { $("#"+self.div).children("div").html(html); } } else if($("#"+self.div).children().size() > 0) { $("#"+self.div).children("div").remove(); } } } this.sort = function(col,btn) { this.sortby = col; if(this.sorted == btn ) {//only change sort direction on current col this.sortdir = (this.sortdir=="DESC"?"ASC":"DESC"); } else { this.sortdir = "ASC"; } if(this.sorted != null) { $(this.sorted).parent().css("background","url("+image_path+"table_header.jpg)"); $(this.sorted).css("background",""); $(this.sorted).css("padding-left","5px"); } $(btn).parent().css("background","url("+image_path+"table_header_over.jpg)"); $(btn).css("background","url("+image_path+"arrow_"+this.sortdir+".png) no-repeat 3px center"); $(btn).css("padding-left","20px"); this.sorted = btn; this.clearSelection(); if(this.loadFunc) { this.loadFunc(); } if ( req ) req.abort(); req = $.post(this.xml, this.postvars() , function(xml) { $("#"+self.div+" table tr:has(td)").remove(); //remove all previous rows self.draw(xml); if(self.completeFunc) { self.completeFunc(); } }); } this.clearSelection = function () { if (document.selection) { document.selection.empty(); } else if (window.getSelection) { window.getSelection().removeAllRanges(); } } this.showhide = function() { for(var i=0; i 0) { this.page = arguments[0]; } if(this.loadFunc) { this.loadFunc(); } if ( req ) req.abort(); req = $.post(this.xml, this.postvars() , function(xml) { $("#"+self.div+" table tr:has(td)").remove(); //remove all previous rows self.showhide(); self.draw(xml); if(self.completeFunc) { self.completeFunc(); } }); } this.postvars = function() { var postvars = {action:"get",sortby:this.sortby, sortdir:this.sortdir, filter:this.filterValue, limit:this.limit, page:this.page, name:this.objName}; for (var custom in this.customVars) { if(typeof(this.customVars[custom]) == "function") { postvars[custom] = this.customVars[custom](); } else { postvars[custom] = this.customVars[custom]; } } return postvars; } this.filter = function(value) { this.page = 0; this.filterValue = value; if(this.loadFunc) { this.loadFunc(); } if ( req ) req.abort(); req = $.post(this.xml, this.postvars() , function(xml) { $("#"+self.div+" table tr:has(td)").remove(); //remove all previous rows self.showhide(); self.draw(xml); if(self.completeFunc) { self.completeFunc(); } }); } this.filtercategory = function(value) { this.page = 0; this.filterCatValue = value; if(this.loadFunc) { this.loadFunc(); } if ( req ) req.abort(); req = $.post(this.xml, this.postvars() , function(xml) { $("#"+self.div+" table tr:has(td)").remove(); //remove all previous rows self.showhide(); self.draw(xml); if(self.completeFunc) { self.completeFunc(); } }); } }