⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sortabletable.js

📁 struts hibernet spring
💻 JS
📖 第 1 页 / 共 2 页
字号:
						var val=dojo.html.renderedTextContent(cells[j]); //	should be the same index as the column.						if(type == String){							o[field]=val;						} else {							if (val!=null){								o[field]=new type(val);							} else {								o[field]=new type();	//	let it use the default.							}						}					}				}				if(dojo.html.hasAttribute(rows[i],"value")&&!o[this.valueField]){					o[this.valueField]=dojo.html.getAttribute(rows[i],"value");				}				//	FIXME: add code to preserve row attributes in __metadata__ field?				this.data.push(o);								//	add it to the selections if selected="true" is present.				if(dojo.html.getAttribute(rows[i],"selected")=="true"){					this.selected.push(o);				}			}		},				showSelections:function(){			var body=this.domNode.getElementsByTagName("tbody")[0];			var rows=body.getElementsByTagName("tr");			var idx=0;			for(var i=0; i<rows.length; i++){				if(rows[i].parentNode==body){					if(dojo.html.getAttribute(rows[i],"selected")=="true"){						rows[i].className=this.rowSelectedClass;					} else {						if(this.enableAlternateRows&&idx%2==1){							rows[i].className=this.rowAlternateClass;						}else{							rows[i].className="";						}					}					idx++;				}			}		},		render:function(bDontPreserve){			//	summary			//	renders the table to the browser			var data=[];			var body=this.domNode.getElementsByTagName("tbody")[0];			if(!bDontPreserve){				//	rebuild data and selection				this.parseDataFromTable(body);			}			//	clone this.data for sorting purposes.			for(var i=0; i<this.data.length; i++){				data.push(this.data[i]);			}						var col=this.columns[this.sortIndex];			if(!col.noSort){				var field=col.getField();				if(col.sortFunction){					var sort=col.sortFunction;				}else{					var sort=function(a,b){						if (a[field]>b[field]) return 1;						if (a[field]<b[field]) return -1;						return 0;					}				}				data.sort(sort);				if(this.sortDirection!=0) data.reverse();			}			//	build the table and pop it in.			while(body.childNodes.length>0) body.removeChild(body.childNodes[0]);			for(var i=0; i<data.length;i++){				var row=document.createElement("tr");				dojo.html.disableSelection(row);				if (data[i][this.valueField]){					row.setAttribute("value",data[i][this.valueField]);				}				if(this.isSelected(data[i])){					row.className=this.rowSelectedClass;					row.setAttribute("selected","true");				} else {					if(this.enableAlternateRows&&i%2==1){						row.className=this.rowAlternateClass;					}				}				for(var j=0;j<this.columns.length;j++){					var cell=document.createElement("td");					cell.setAttribute("align", this.columns[j].align);					cell.setAttribute("valign", this.columns[j].valign);					dojo.html.disableSelection(cell);					if(this.sortIndex==j){						cell.className=this.columnSelected;					}					if(this.columns[j].sortType=="__markup__"){						cell.innerHTML=data[i][this.columns[j].getField()];						for(var k=0; k<cell.childNodes.length; k++){							var node=cell.childNodes[k];							if(node&&node.nodeType==dojo.html.ELEMENT_NODE){								dojo.html.disableSelection(node);							}						}					}else{						if(this.columns[j].getType()==Date){							var format=this.defaultDateFormat;							if(this.columns[j].format) format=this.columns[j].format;							cell.appendChild(document.createTextNode(dojo.date.strftime(data[i][this.columns[j].getField()], format)));						}else{							cell.appendChild(document.createTextNode(data[i][this.columns[j].getField()]));						}					}					row.appendChild(cell);				}				body.appendChild(row);				dojo.event.connect(row, "onclick", this, "onUISelect");			}						//	if minRows exist.			var minRows=parseInt(this.minRows);			if (!isNaN(minRows) && minRows>0 && data.length<minRows){				var mod=0;				if(data.length%2==0) mod=1;				var nRows=minRows-data.length;				for(var i=0; i<nRows; i++){					var row=document.createElement("tr");					row.setAttribute("ignoreIfParsed","true");					if(this.enableAlternateRows&&i%2==mod){						row.className=this.rowAlternateClass;					}					for(var j=0;j<this.columns.length;j++){						var cell=document.createElement("td");						cell.appendChild(document.createTextNode("\u00A0"));						row.appendChild(cell);					}					body.appendChild(row);				}			}		},		//	the following the user can override.		onSelect:function(/* DomEvent */ e){ 			//	summary			//	empty function for the user to attach code to, fired by onUISelect		},		onUISelect:function(/* DomEvent */ e){			//	summary			//	fired when a user selects a row			var row=dojo.html.getParentByType(e.target,"tr");			var body=dojo.html.getParentByType(row,"tbody");			if(this.enableMultipleSelect){				if(e.metaKey||e.ctrlKey){					if(this.isSelected(this.getObjectFromRow(row))){						this.removeFromSelected(this.getObjectFromRow(row));						row.removeAttribute("selected");					}else{						//	push onto the selection stack.						this.setSelectionByRow(row);						row.setAttribute("selected","true");					}				}else if(e.shiftKey){					//	the tricky one.  We need to figure out the *last* selected row above, 					//	and select all the rows in between.					var startRow;					var rows=body.getElementsByTagName("tr");					//	if there's a selection above, we go with that first. 					for(var i=0;i<rows.length;i++){						if(rows[i].parentNode==body){							if(rows[i]==row) break;							if(dojo.html.getAttribute(rows[i],"selected")=="true"){								startRow=rows[i];							}						}					}					//	if there isn't a selection above, we continue with a selection below.					if(!startRow){						startRow=row;						for(;i<rows.length;i++){							if(dojo.html.getAttribute(rows[i],"selected")=="true"){								row=rows[i];								break;							}						}					}					this.resetSelections(body);					if(startRow==row){						//	this is the only selection						row.setAttribute("selected","true");						this.setSelectionByRow(row);					}else{						var doSelect=false;						for(var i=0; i<rows.length; i++){							if(rows[i].parentNode==body){								rows[i].removeAttribute("selected");								if(rows[i]==startRow){									doSelect=true;								}								if(doSelect){									this.setSelectionByRow(rows[i]);									rows[i].setAttribute("selected","true");								}								if(rows[i]==row){									doSelect=false;								}							}						}					}				}else{					//	reset the selection					this.resetSelections(body);					row.setAttribute("selected","true");					this.setSelectionByRow(row);				}			}else{				//	reset the data selection and go.				this.resetSelections(body);				row.setAttribute("selected","true");				this.setSelectionByRow(row);			}			this.showSelections();			this.onSelect(e);			e.stopPropagation();			e.preventDefault();		},		onHeaderClick:function(/* DomEvent */ e){			//	summary			//	Main handler function for each header column click.			var oldIndex=this.sortIndex;			var oldDirection=this.sortDirection;			var source=e.target;			var row=dojo.html.getParentByType(source,"tr");			var cellTag="td";			if(row.getElementsByTagName(cellTag).length==0) cellTag="th";			var headers=row.getElementsByTagName(cellTag);			var header=dojo.html.getParentByType(source,cellTag);						for(var i=0; i<headers.length; i++){				if(headers[i]==header){					if(i!=oldIndex){						//	new col.						this.sortIndex=i;						this.sortDirection=0;						headers[i].className=this.headerSortDownClass					}else{						this.sortDirection=(oldDirection==0)?1:0;						if(this.sortDirection==0){							headers[i].className=this.headerSortDownClass;						}else{							headers[i].className=this.headerSortUpClass;						}					}				}else{					//	reset the header class.					headers[i].className=this.headerClass;				}			}			this.render();		},		postCreate:function(){ 			// 	summary			//	overridden from HtmlWidget, initializes and renders the widget.			var thead=this.domNode.getElementsByTagName("thead")[0];			if(this.headClass.length>0){				thead.className=this.headClass;			}			//	disable selections			dojo.html.disableSelection(this.domNode);			//	parse the columns.			this.parseColumns(thead);			//	attach header handlers.			var header="td";			if(thead.getElementsByTagName(header).length==0) header="th";			var headers=thead.getElementsByTagName(header);			for(var i=0; i<headers.length; i++){				if(!this.columns[i].noSort){					dojo.event.connect(headers[i], "onclick", this, "onHeaderClick");				}				if(this.sortIndex==i){					if(this.sortDirection==0){						headers[i].className=this.headerSortDownClass;					}else{						headers[i].className=this.headerSortUpClass;					}				}			}			//	parse the tbody element and re-render it.			var tbody=this.domNode.getElementsByTagName("tbody")[0];			if (this.tbodyClass.length>0) {				tbody.className=this.tbodyClass;			}			this.parseDataFromTable(tbody);			this.render(true);		}	});

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -