Auntion-TableSort javascript类文件第1/2页

时间:2021-05-28

tableSort.class.js
复制代码 代码如下:
/*
*表格名不能为空,可为已获取的对象或名字
*表头名默认为:tag
*通过自行编写接口可实现不同的触发排序方式
*
*作者:Auntion
*E-mail:Auntion@Gmail.com
*OICQ:82874972
*
*日期:2007年04月22日-测试-待修正
*/

vartableSort=function(element,tagName,upStyle,downStyle){this.table=(typeof(element)=='string')?TAGDom.fromId(element):element;this.td=this.table.getElementsByTagName("td");this.hName=(tagName.length<1)?"tag":tagName;this.rows=this.table.rows;this.byUp=(upStyle==undefined)?"DescUp":upStyle;this.byDown=(downStyle==undefined)?"DescDown":downStyle;vartotalTd=[];vartotalNr=[];vartotalTag=[];this.tempCellIndex;this.tempStatus={};varsetAllTag=function(){for(vari=0;i<this.td.length;i++){if(this.td[i].className===this.hName)totalTag.push(this.td[i]);}}.bind(this);vargetStatus=function(tagName){this.tempStatus[tagName]=(this.tempStatus[tagName]==true)?false:true;for(tagsinthis.tempStatus){if(tags==tagName)returnthis.tempStatus[tags];elsedeletethis.tempStatus[tags];}}.bind(this);varchangeShow=function(cellIn,status){for(vari=0;i<totalTag.length;i++){if(totalTag[i].cellIndex==cellIn){if(status==true)totalTag[i].className=this.byUp;elseif(status==false)totalTag[i].className=this.byDown;}else{totalTag[i].className=this.hName;}}}.bind(this);varstartSort=function(status){for(vari=totalNr[this.tempCellIndex].length-1;i>0;i--){for(varj=0;j<i;++j){if((status==true)?totalNr[this.tempCellIndex][j]>totalNr[this.tempCellIndex][j+1]:totalNr[this.tempCellIndex][j]<totalNr[this.tempCellIndex][j+1]){vartemp=totalNr[this.tempCellIndex][j+1];totalNr[this.tempCellIndex][j+1]=totalNr[this.tempCellIndex][j];totalNr[this.tempCellIndex][j]=temp;for(varn=0;n<totalNr.length;n++){if(n!=this.tempCellIndex){vartemps=totalNr[n][j+1];totalNr[n][j+1]=totalNr[n][j];totalNr[n][j]=temps;}}}}};InsertContect();}.bind(this);varInsertContect=function(){for(vari=0;i<totalTd.length;i++){for(varj=0;j<totalTd[i].length;j++){totalTd[i][j].innerHTML=totalNr[i][j];}};totalTd.length=0;totalNr.length=0;};this.init=function(status){for(vari=0;i<(this.td.length/this.rows.length);i++){totalTd[i]=newArray();totalNr[i]=newArray();for(varj=0;j<this.rows.length;j++){if(this.rows[j].cells[i].className!==this.hName){totalTd[i][j-1]=this.rows[j].cells[i];if(IsNumber(this.rows[j].cells[i].innerHTML)==true){totalNr[i][j-1]=parseInt(this.rows[j].cells[i].innerHTML);}else{totalNr[i][j-1]=this.rows[j].cells[i].innerHTML;}}}}startSort(status);}

/********************************************************************************************************************************/

/**通过点击标签触发排序事件**/
//public:通过默认鼠标事键触发(interfaceexample)(设置用户接口的范例)
this.toTagStart=function(){
setAllTag();//获取标签
for(vari=0;i<totalTag.length;i++){
totalTag[i].sIndex=function(cIndex){this.tempCellIndex=cIndex}.bind(this);//设置列index
totalTag[i].gStatus=function(values){returngetStatus(values)};//获取与设置状态
totalTag[i].ceShow=function(i,s){changeShow(i,s)};//改变显示的东西
totalTag[i].stSort=function(status){this.init(status)}.bind(this);//初始化
totalTag[i].onselectstart=function(){returnfalse};//点击不选中文字
totalTag[i].onclick=function(){
this.sIndex(this.cellIndex);
this.status=this.gStatus(this.firstChild.nodeValue);
this.ceShow(this.cellIndex,this.status);
this.stSort(this.status);
}

}
}

}

Language.ext.js
复制代码 代码如下:
/*
*
ByAuntion

QQ:82874972

Blog:Auntion@blogbus.com

Email:Auntion@Gmail.com

请勿删除此部分注释.谢谢!

verdate-2007-02-01
*
*/
varisIe=/msie/i.test(navigator.userAgent);
varTAGDom={
fromId:function(i){
returndocument.getElementById(i);
},
fromName:function(i){
returndocument.getElementById(i);
},
fromClass:function(className,baseId){
this.fatherId=null;
if(!baseId){
this.fatherId=document;
}else{
this.fatherId=DOM.fromId(baseId);
}
varbasic=fatherId.getElementsByTagName("*")||document.all;
varchild=null;
varclassNames=null;

varaggregate=[];
for(vari=0;i<basic.length;i++){
child=basic[i];
classNames=child.className.split("");
for(varj=0;j<classNames.length;j++){
if(classNames[j]==className){
aggregate.push(child);
break;
}
}
}
returnaggregate;
}
};
functionexternalStyle(element,target){
this.setReturn;
if(element.currentStyle){
this.setReturn=element.currentStyle[target];
}elseif(window.getComputedStyle){
this.setReturn=getComputedStyle(element,"").getPropertyValue(target);
}
returnthis.setReturn;
}
String.prototype.toInt=function(){
returnparseInt(this.replace(/[a-zA-Z]+/,''));
}
String.prototype.trim=function(){
returnthis.replace(/(^\s*)|(\s*$)/g,"");
}
Function.prototype.bind=function(e){
varsource=this;
returnfunction(){
returnsource.apply(e,arguments);
}
}
functionIsNumber(_str){
vartmp_str=_str.trim();
varpattern=/^(-¦\+)?\d+(\d+)?$/;
returnpattern.test(tmp_str);
}

使用实例_1.htm
12下一页阅读全文

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章