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

📄 grid.js

📁 java script web控件 包含了树 列表 表单的操作
💻 JS
📖 第 1 页 / 共 4 页
字号:
	this.getLockedTable = function(){
		return lockedTable;
	}
	
	this.getUnLockedTable = function(){
		return unLockedTable;
	}

	this.getElement = function(){
		return element;
	}

	this.setHeight = function(h){
		element.style.height = h;
	}

	this.setWidth = function(w){
		element.style.width = w;
	}

	this.calcRowsHeight = function(data){
		if(data==null)
			data = oThis.getValue();
		if(context.sum == null || context.sum.length==0){
			return data.length * 20;
		}else{
			return data.length * 20 + 20;
		}
		
	}

	this.setContext = function(_context){
		context = _context;
		this.context = context;
	}

	this.getSelectedRows = function(){
		return selectedRows;
	}

	this.calcColsWidth = function(locked){
		var width = 0;
		var cols = null;
		if("true" == locked){
			if(context.checkBox == true){
				width = width + 40;
			}else if(context.radioBox == true){
				width = width + 40;
			}

			if(context.sequence == true){
				width = width + 40;
			}

			cols = oThis.getLockedColumns();
		}else
			cols = oThis.getUnLockedColumns();

		
		
		for(var i=0;i<cols.length;i++){
			var col = cols[i];
			width = width + oThis.getColumnWidth(col);
		}
		return width;
	}

	this.clearData = function(){
		var currentTable = element.all("lockedTable");
		var rowNum = currentTable.rows.length;
		
		for(var i=rowNum-1;i>=0;i--){
			currentTable.deleteRow();
		}
		currentTable =  element.all("unLockedTable");
		rowNum = currentTable.rows.length;
		for(var i=rowNum-1;i>=0;i--){
			currentTable.deleteRow();
		}
	}

	this.getColumnOption = function(column,id){
		var options = column.options;
		for(var i=0;i<options.length;i++){
			var op = options[i];
			if(op.id == id){
				return op;
			}
		}
		return null;
	}

	this.isVScrollerNeeded = function(){
		var dataHeight = oThis.calcRowsHeight(value);
		var headerHeight = 20;

		if(dataHeight + headerHeight + hscrollerHeight>element.offsetHeight){
			vscrollerWidth = 17;
			return true;
		}else{
			vscrollerWidth = 0;
			return false;
		}
	}

	this.isHScrollerNeeded = function(){
		var totalWidth = element.offsetWidth;
		var lockedWidth = oThis.calcColsWidth("true");
		var unLockedWidth = oThis.calcColsWidth("false");
		if(unLockedWidth==0){
			hscrollerHeight = 0;
			return false;
		}

		if((totalWidth - lockedWidth - vscrollerWidth) >= unLockedWidth){
			hscrollerHeight = 0;
			return false;
		}else{
			hscrollerHeight = 17;
			return true;
		}
	}


	//刷新滚动条
	this.refreshScrollers = function(){
		try{
		hscrollerHeight = 0;
		vscrollerWidth = 0;
		/*
		先计算纵向滚动条是否需要
		再计算横向滚动条是否需要,计算时考虑纵向滚动条占据的宽度,如果横向滚动条需要,那么重新计算纵向滚动条是否需要
		*/
		var vscrollerNeeded = oThis.isVScrollerNeeded();
		var hscrollerNeeded = oThis.isHScrollerNeeded();
		if(hscrollerNeeded)
			vscrollerNeeded = oThis.isVScrollerNeeded();
		



		var scrollersPane = element.all("scrollers");
		scrollersPane.style.top = 0;
		scrollersPane.style.left = 0;
		scrollersPane.style.width = element.offsetWidth;
		scrollersPane.style.height = element.offsetHeight;
		

		//定义各个div的尺寸
		
		//非锁定列显示宽度
		var unLockedColumnDisplayWidth = oThis.calcUnLockedColumnDisplayWidth();
		//显示数据区域高度
		var dataDisplayHeight = oThis.calcDataDisplayHeight();
		//锁定列宽度
		var lockedColsWidth = oThis.calcColsWidth("true");
		
		//非锁定列总宽度,该宽度大于等于非锁定列显示宽度
		var unLockedColsWidth = oThis.calcColsWidth("false");
		var dataDisplayWidth = unLockedColumnDisplayWidth + lockedColsWidth;
		
		if(dataDisplayWidth>(element.offsetWidth-vscrollerWidth)){
			dataDisplayWidth = element.offsetWidth-vscrollerWidth;
		}

		element.all("headerArea").style.width = dataDisplayWidth;  //总宽度
		element.all("lockedHeader").style.width = lockedColsWidth;  //锁定列头宽度
		element.all("unLockedHeader").style.left = lockedColsWidth;    //非锁定列左边位置
		element.all("unLockedHeader").style.width = unLockedColumnDisplayWidth;
		element.all("unLockedArea").style.width = unLockedColumnDisplayWidth;
		
		element.all("dataArea").style.height = dataDisplayHeight;
		element.all("dataArea").style.width = dataDisplayWidth;
		
		element.all("lockedArea").style.width = lockedColsWidth;
		element.all("lockedArea").style.height = oThis.calcRowsHeight(value);
		element.all("unLockedArea").style.left = lockedColsWidth ;
		element.all("unLockedArea").style.width = unLockedColumnDisplayWidth
		element.all("unLockedArea").style.height = oThis.calcRowsHeight(value);
		

		//纵向滚动条

		var VScroller = element.all("VScroller");

		if(vscrollerNeeded){
			VScroller.style.display = "";
			VScroller.style.width = vscrollerWidth + 1;
			VScroller.style.height = dataDisplayHeight + headerHeight;
			VScroller.style.left = element.offsetWidth - vscrollerWidth - 1;
			VScroller.style.border = "1 solid #5177A8";
			VScroller.style.borderTop = 0;
			VScroller.style.borderLeft = 0;

			var virtualVArea = element.all("virtualVArea");
			virtualVArea.style.width = 1;
			virtualVArea.style.fontSize = 1;
			virtualVArea.style.height = oThis.calcRowsHeight(value) + headerHeight + hscrollerHeight;

			
			VScroller.onscroll = function(){
				element.all("dataArea").scrollTop  =  this.scrollTop;
			}
		}else{
			VScroller.style.display = "none";
		}



		//横向滚动条
		var HScroller = element.all("HScroller");
		if(hscrollerNeeded){
			HScroller.style.display = "";
			var left = oThis.calcColsWidth("true");
			HScroller.style.left = left;
			HScroller.style.width = element.offsetWidth - left - vscrollerWidth;
			HScroller.style.height = 20;
			HScroller.style.top = dataDisplayHeight + headerHeight-5;
			
			var virtualHArea = element.all("virtualHArea");
			virtualHArea.style.height = 1;
			virtualHArea.style.fontSize = 1;
			virtualHArea.style.width = oThis.calcColsWidth("false")-2;
			
			HScroller.onscroll = function(){
				element.all("unLockedHeader").scrollLeft  =  this.scrollLeft;
				element.all("unLockedArea").scrollLeft = this.scrollLeft;
			}
		}else{
			HScroller.style.display = "none";
		}
		}catch(e){
			;
		}
	}

	
	

	/**
	 * 计算非锁定列区域显示宽度
	 */
	this.calcUnLockedColumnDisplayWidth = function(){
		var totalWidth = element.offsetWidth;
		var lockedWidth = oThis.calcColsWidth("true");
		var r = totalWidth - lockedWidth -vscrollerWidth;
		if(r>oThis.calcColsWidth("false")){
			r = oThis.calcColsWidth("false")
		}else if(r<0){
			r = 0;
		}
		return r;
	}
	
	/**
	 * 计算数据显示区域的高度
	 */
	this.calcDataDisplayHeight = function(){
		var totalHeight = element.offsetHeight;
		var r = totalHeight - headerHeight - hscrollerHeight;
		var rowsHeight = oThis.calcRowsHeight();

		if(r>rowsHeight){
			r = rowsHeight;
		}
		return r;
	}

	this.getValue = function(){
		return value;
	}

	this.getValueAsString = function(){
		return toString(value);
	}

	this.refreshSequence = function(from){
		for(var i=from;i<rows.length;i++){
			rows[i].setSequence((i+1));
		}
	}

	this.deleteRow = function(i){
		if(i<0 || i>rows.length){
			alert("非法参数");
			return;
		}
		oThis.postAdd_Delete()
		var currentTable = element.all("lockedTable");
		currentTable.deleteRow(i);
		currentTable =  element.all("unLockedTable");
		currentTable.deleteRow(i);
		selectedRows.remove(rows[i]);
		rows.removeAt(i);
		oThis.refreshSequence(i);
		oThis.refreshScrollers();
		value.removeAt(i);
		oThis.afterAdd_Delete();
	}


	this.deleteSelectedRows = function(){
		if(selectedRows.length<=0){
			return ;
		}
		oThis.postAdd_Delete()
		var index = 0;
		var indexs = [];
		for(var i=0;i<selectedRows.length;i++){
			index = selectedRows[i].getSequence()-1;
			indexs[indexs.length] = index;
		}
		indexs.sortBy(1);
		for(var i=indexs.length-1;i>=0;i--){
			index = indexs[i];
			var currentTable = element.all("lockedTable");
			currentTable.deleteRow(index);
			currentTable = element.all("unLockedTable");
			currentTable.deleteRow(index);
			rows.removeAt(index);
			value.removeAt(index);
		}
		selectedRows.removeAll();
		oThis.refreshSequence(0);
		oThis.refreshScrollers();
		oThis.afterAdd_Delete();
	}

	this.getValueOfSelectedRows = function(){
		var r = [];
		for(var i=0;i<selectedRows.length;i++){
			var row = selectedRows[i];
			r[i] = row.value;
		}
		return r;
	}

	/**
	 *	取所有选中行里某列的值
	 */
	this.getColumnValueOfSelectedRows = function(propertyName){
		var r = [];
		for(var i=0;i<selectedRows.length;i++){
			var row = selectedRows[i];
			r[i] = oThis.getPropertyOfRow(row,propertyName);
		}
		return r;
	}

	this.getColumnValues = function(propertyName){
		var r = [];
		for(var i=0;i<rows.length;i++){
			var row = rows[i];
			r[i] = oThis.getPropertyOfRow(row,propertyName);
		}
		return r;
	}

	this.getPropertyOfRow = function(row,pName){
		var column = oThis.getColumnByName(pName);
		if(column!=null){
			var cell = row.cells[pName];
			oThis.debug("to get cell value");
			return cell.getValue();
		}
		obj = row.value;
		if(obj==null){
			return null;
		}
		var name = pName;
		var ns = name.split(".");
		if(ns[1]=="")
			ns.removeAt(1);

		if(ns.length>1){
			for(var i=0;i<ns.length-1;i++){
				var parent = obj;
				obj = parent[ns[i]];
				if(obj==null){
					return null;
				}
			}
			obj = obj[ns[ns.length-1]];
		}else{
			obj = obj[pName];
		}
		return obj;
	}

	


	this.postAdd_Delete = function(){
		if(rows.length<=0)
			return;
		var row = rows[rows.length-1];
		var autoCells = row.autoCreatedCell;
		if(context.sequence==true){
			autoCells["auto_sequence"].className = "";
		}
		if(context.checkBox == true || context.radioBox == true)
			autoCells["auto_checkbox"].className = "";
		var cells = row.cells;
		for(var i=0;i<columns.length;i++){
			var column = columns[i];
			cells[column.name].element.className = "";
		}
		
	}

	this.afterAdd_Delete = function(){
		if(rows.length<=0)
			return;
		var row = rows[rows.length-1];
		var autoCells = row.autoCreatedCell;
		if(context.sum==null || context.sum.length==0){
			if(context.sequence==true){
				autoCells["auto_sequence"].className = "lastRow";
			}
			if(context.checkBox == true)
				autoCells["auto_checkbox"].className = "lastRow";
			var cells = row.cells;
			for(var i=0;i<columns.length;i++){
				var column = columns[i];
				cells[column.name].element.className = "lastRow";
			}
		}
		if(oThis.sumRow!=null){
			oThis.sumRow.refresh();
		}
	}

	this.addRow = function(_data){
		oThis.postAdd_Delete()
		value[value.length]=_data;
		var row = new SigmaRow(oThis,value.length-1);
		rows[value.length-1] = row;
		oThis.refreshScrollers();
		oThis.afterAdd_Delete();
		return row;
	}

	this.addNewRow = function(){
		oThis.postAdd_Delete();
		var rowData = new Object();
		for(var i=0;i<columns.length;i++){
			var cellData = null;
			var column = columns[i];
			if(column.defaultValue!=null){
				cellData = column.defaultValue;
			}else if(column.mode=="string"||column.mode == "function"){
				cellData = null;
			}else if(column.mode=="number" || column.mode=="money"){
				cellData = 0;
			}else if(column.mode=="check" || column.mode=="radio"){
				cellData = false;
			}else if(column.mode == "select"){

⌨️ 快捷键说明

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