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

📄 grid.js

📁 进销存软件源代码
💻 JS
📖 第 1 页 / 共 2 页
字号:
var testUndefine;

function ZYDGRIDTITLE(text,align,width,height,bgColor,color,isNumeric){
	this.text=serversidename='';
	this.text=text;
	this.align=align;
	this.width=width;
	this.height=height;
	this.bgColor=bgColor;
	this.color=color;
	this.isNumeric=isNumeric;
	this.formAlign='left';
	this.isTotal=0;
	this.formTotal=0;
	this.order=-1;
	this.param;
}

function ZYDGRIDFORIEBUG(){
	this.zydgrid=0;

	this.refresh=function(eo,i,j,ft){
		var nc=eo.grid.rows(i).cells(j);
		if (eo.showpos<0)eo.showpos=0;
		if (eo.isTotalRow && i==eo.grid.rows.length-1){
			if (j==0)nc.innerHTML='∑';
			else if (eo.title[j].isTotal){
				nc.innerHTML=eo.cb_getdataHTML(eo.title[j].formTotal);
				nc.align=eo.title[j].formAlign;
			}
		}else if (i&&j){
			var data;
			if (eo.data[eo.showpos+i-1])
				data=eo.data[eo.showpos+i-1][j-1];
			else
				data='';
			nc.innerHTML=eo.cb_getdataHTML(data==testUndefine?'':data);
			nc.align=eo.title[j].formAlign;
		}
		else{
			var zgi=(i==0?eo.title[i==0?j:i]:eo.vtitle[i==0?j:i])
			nc.innerHTML=(i!=0&&j==0)?(eo.showpos+i):eo.cb_getdataHTML(zgi.text);
			if (i==0&&j>0)nc.innerHTML+=(eo.title[j].order==-1?'':((eo.title[j].order==0?'↑':'↓')));
			if (ft!=1){
				nc.width=zgi.width;
				nc.height=zgi.height;
				nc.bgColor=zgi.bgColor;
				nc.style.color=zgi.color;
				nc.align=zgi.align;
			}
		}
	}

	this.refreshAll=function(extobj,x,y,ft){
		var i,j,is,js,eo=extobj.zydgrid;
		if (isNaN(parseInt(x))) is=0; else is=parseInt(x);
		if (isNaN(parseInt(y))) js=0; else js=parseInt(y);
		for (i=is;i<=eo.rows+(eo.isTotalRow?1:0);i++)
			for (j=js;j<=eo.cols;j++)
				extobj.refresh(eo,i,j,ft);
		if (eo.data.length>eo.rows) eo.pagectrl.style.display='block';
	}

	this.GotoPos=function(extobj,x){
		var that=extobj.zydgrid,newpos;
		if (isNaN(parseInt(x))){
			that.txtPosValue.value=that.showpos+1;
			return;
		}
		newpos=parseInt(x);
		if (newpos>that.data.length) newpos=that.data.length;
		if (newpos<1) newpos=1;
		that.showpos=newpos-1;
		that.txtPosValue.value=that.showpos+1;
		extobj.refreshAll(extobj,1,0);
	}
}

function ZYDGRID(extobj,id,rows,cols,width,height,isTotalRow,cb_getdataHTML,extdata,eventcallback){
	this.extobj=extobj;
	this.id=id;
	this.data=(typeof(extdata)=='object'?extdata:new Array());
	this.title=new Array();
	this.vtitle=new Array();
	this.showpos=0;
	this.rows=parseInt(rows);
	this.cols=parseInt(cols);
	this.width=width;
	this.height=height;
	this.lineStyle='solid';
	this.gridBgColor='#C7E9FE';
	this.isCapture=0;
	
	this.saveX=0;
	this.saveWidth=0;
	this.saveTableWidth=0;
	this.isCapture=0;
	this.isTotalRow=isTotalRow;
	this.captureElement;

	this.eventcb=function(eo,msg,p1,p2){
		return;
	}
	this.eventcallback=(typeof(eventcallback)=='function'?eventcallback:this.eventcb);
	
	this.cbdef_getdataHTML=function (data,i,j){
		if (String(data)=='') return '&nbsp;';
		return String(data);
	}
	this.cb_getdataHTML=this.cbdef_getdataHTML;

	this.hexch = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
	
	this.ToHex = function(n){
		var h, l;

		n = Math.round(n);
		if(n > 255)n = 255;
		l = n % 16;
		h = Math.floor((n / 16)) % 16;
		return (this.hexch[h] + this.hexch[l]);
	}

	this.GetDark = function(c){
		var r, g, b;
		r = '0x' + c.substr(1, 2);g = '0x' + c.substr(3, 2);b = '0x' + c.substr(5, 2);
		this.mColor3 = '#' + this.ToHex(r * 2 / 3) + this.ToHex(g * 2 / 3) + this.ToHex(b * 2 / 3);
	}

	this.GetLight = function(c){
		var r, g, b;
		r = '0x' + c.substr(1, 2);g = '0x' + c.substr(3, 2);b = '0x' + c.substr(5, 2);
		return '#' + this.ToHex(256 - (256 - r) / 3) + this.ToHex(256 - (256 - g) / 3) + this.ToHex(256 - (256 - b) / 3);
	}

	var tdSortOrder, tdSortPos;
	
	function compareNumbers(a, b){
		var ret=0, e;
		if (tdSortOrder) return b[tdSortPos] - a[tdSortPos];
		else return a[tdSortPos] - b[tdSortPos];
	}

	function compareStrings(a, b){
		if (tdSortOrder){
			if (a[tdSortPos] > b[tdSortPos])	return -1;
			if (a[tdSortPos] < b[tdSortPos])	return 1;
			return 0;
		}
		else{
			if (a[tdSortPos] > b[tdSortPos])	return 1;
			if (a[tdSortPos] < b[tdSortPos])	return -1;
			return 0;
		}
	}

	this.sort=function(eo,pos){
		if (pos<1||pos>eo.cols) return (false);
		if (eo.title[pos].order!=-1){
			if (eo.title[pos].order==0)eo.title[pos].order=1;
			else eo.title[pos].order=0;
		}
		else{
			for (var i=0;i<eo.title.length;i++)eo.title[i].order=-1;
			eo.title[pos].order=0;
		}
		tdSortPos = pos-1;
		tdSortOrder = eo.title[pos].order;
		if (eo.title[pos].isNumeric) eo.data.sort(compareNumbers);
		else eo.data.sort(compareStrings);
		eo.refreshAll(0,0,1);
		return (true);
	}
	
	this.calcTotal=function(){
		var i, j, x;
		
		for (j=0;j<this.cols;j++){
			if (!this.title[j+1].isTotal)continue;
			this.title[j+1].formTotal=0;
			for (i=0;i<this.data.length;i++){
				try{x=parseFloat(this.data[i][j]);
				}catch(e){}
				if (!isNaN(x))this.title[j+1].formTotal=fixFloat(this.title[j+1].formTotal+x,2);
			}
		}
	}
	
	this.saveRowUnSelectedBgColor=this.gridBgColor;
	this.saveRowSelectedBgColor='#FFD750';
	this.onmove=function(){
		var e,x,y;
		e=window.event.srcElement;
		try{while(e.tagName!='TD') e=e.parentElement;}
		catch(e){return;}
		x=e.parentElement.rowIndex-1;
		y=e.cellIndex-1;
		if (extobj.zydgrid.eventcallback(extobj.zydgrid,'MOUSEMOVE',x,y)!=0){
			e.parentElement.bgColor=extobj.zydgrid.saveRowSelectedBgColor;
		}
	}
	this.onout=function(){
		var e,x,y;
		e=window.event.srcElement;
		try{while(e.tagName!='TD') e=e.parentElement;}
		catch(e){return;}
		x=e.parentElement.rowIndex-1;
		y=e.cellIndex-1;
		if (extobj.zydgrid.eventcallback(extobj.zydgrid,'MOUSEOUT',x,y)!=0){
			e.parentElement.bgColor=extobj.zydgrid.saveRowUnSelectedBgColor;
		}
	}
	this.onclick=function(){
		var e,x,y;
		e=window.event.srcElement;
		try{while(e.tagName!='TD') e=e.parentElement;}
		catch(e){return;}
		x=e.parentElement.rowIndex-1;
		y=e.cellIndex-1;
		extobj.zydgrid.eventcallback(extobj.zydgrid,'MOUSECLICK',x,y);
	}
	this.oncontextmenu=function(){
		var e,x,y;
		e=window.event.srcElement;
		try{while(e.tagName!='TD') e=e.parentElement;}
		catch(e){return;}
		x=e.parentElement.rowIndex-1;
		y=e.cellIndex-1;
		window.status=x+','+y;
		if (extobj.zydgrid.eventcallback(extobj.zydgrid,'RIGHTCLICK',x,y)==true)window.event.returnValue=false;
	}
	
	this.onmousemove=function(){
		var e,x,mx,t;
		e=window.event.srcElement;
		try{while(e.tagName!='TD') e=e.parentElement;}
		catch(e){return;}
		switch (this.isCapture){
			case 1:
				mx=window.event.screenX;
				x=this.saveWidth+mx-this.saveX+2;
				if (x<1) x=1;
				this.captureElement.width=x;
				t=id.all.tags('TABLE')(0);
				if (x==1) t.width=this.saveTableWidth-this.saveWidth+1;
				else t.width=this.saveTableWidth+mx-this.saveX+2;
				return;
			case 2:
				mx=window.event.screenY;
				x=this.saveWidth+mx-this.saveX+2;
				if (x<1) x=1;
				this.captureElement.parentElement.height=x;
				return;
		}
		if (window.event.offsetX>=e.clientWidth-3&&window.event.offsetX<=e.clientWidth) e.style.cursor='E-resize';
		else if (window.event.offsetY>=e.clientHeight-3&&window.event.offsetY<=e.clientHeight) e.style.cursor='S-resize';
		else e.style.cursor='default';
	}
	
	this.onmouseout=function(){
		var e;
		e=window.event.srcElement;
		try{while(e.tagName!='TD') e=e.parentElement;}
		catch(e){return;}
		e.style.cursor='default';
	}

	this.onmouseup=function(){
		document.releaseCapture();
		this.isCapture=0;
	}

	this.onmousedown=function(){
		var e,x,y;
		e=window.event.srcElement;
		try{while(e.tagName!='TD') e=e.parentElement;}
		catch(e){return;}
		x=e.parentElement.rowIndex;
		y=e.cellIndex;
		if (window.event.offsetX>=e.clientWidth-3&&window.event.offsetX<=e.clientWidth&&y>0){
			this.saveX=window.event.screenX;
			this.saveWidth=e.clientWidth;
			this.saveTableWidth=id.all.tags('TABLE')(0).clientWidth;
			this.captureElement=e;
			this.isCapture=1;
		}
		else if (window.event.offsetY>=e.clientHeight-3&&window.event.offsetY<=e.clientHeight&&x>0){
			x=e.parentElement.rowIndex;
			y=e.cellIndex;
			this.saveX=window.event.screenY;
			this.saveWidth=e.clientHeight;
			this.saveTableWidth=id.all.tags('TABLE')(0).clientHeight;
			this.captureElement=e;
			this.isCapture=2;
		}else if(x==0){
			var that=extobj.zydgrid;
			that.sort(that,y);
		}

⌨️ 快捷键说明

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