/** 设置TD隐藏或显示 by 20140814 **/ function cellHidden(cell, state) { if ((state) && (cell.style.display != "none")) { cell.style.display = "none"; }; if ((!state) && (cell.style.display == "none")) { cell.style.display = ""; }; }
this.rowsBuffer = dhtmlxArray(); this.rowsCol = dhtmlxArray(); /** 列是否隐藏-数组 by 20140814 **/ this.colHiddenArr = {};
this.setColumnSizes = function(gridWidth) { var summ = 0; var fcols = []; for (var i = 0; i < this._cCount; i++) { if ((this.initCellWidth[i] == "*") && !this._hrrar[i]) { this._awdth = false; fcols.push(i); continue }; if (this.cellWidthType == '%') { if (typeof this.cellWidthPC[i] == "undefined") this.cellWidthPC[i] = this.initCellWidth[i]; this.cellWidthPX[i] = Math.floor(gridWidth * this.cellWidthPC[i] / 100) || 0 } else { if (typeof this.cellWidthPX[i] == "undefined") this.cellWidthPX[i] = this.initCellWidth[i] }; /** 计算列总宽度时,忽略隐藏列 by 20140814 **/ if (!this._hrrar[i] && !this.colHiddenArr[i]) summ += this.cellWidthPX[i] * 1 }; if (fcols.length) { var ms = Math.floor((gridWidth - summ) / fcols.length); if (ms < 0) ms = 1; for (var i = 0; i < fcols.length; i++) { var next = Math.max((this._drsclmW ? this._drsclmW[fcols[i]] : 0), ms) this.cellWidthPX[fcols[i]] = next; summ += next }; this._setAutoResize() }; this.obj.style.width = summ + "px"; this.hdr.style.width = summ + "px"; if (this.ftr) this.ftr.style.width = summ + "px"; this.chngCellWidth(); return summ };
this.chngCellWidth = function() { if ((_isOpera) && (this.ftr)) this.ftr.width = this.objBox.scrollWidth + "px"; var l = this._cCount; for (var i = 0; i < l; i++) { this.hdr.rows[0].cells[i].style.width = this.cellWidthPX[i] + "px"; this.obj.rows[0].childNodes[i].style.width = this.cellWidthPX[i] + "px"; if (this.ftr) this.ftr.rows[0].cells[i].style.width = this.cellWidthPX[i] + "px" /** 针对列表中已有数据和列,判断隐藏|显示 by 20140814 **/ cellHidden(this.hdr.rows[0].childNodes[i], this.colHiddenArr[i]); cellHidden(this.obj.rows[0].childNodes[i], this.colHiddenArr[i]); if (this.ftr) cellHidden(this.ftr.rows[0].cells[i], this.colHiddenArr[i]); } };
setRowHidden : function (id, state) {}, /** 设置列隐藏|显示 by qiugq 20140814 **/ setColumnHidden : function(cin, state) { this.colHiddenArr[cin] = state; var z = this.hdr.rows[1]; for (var i = 0; i < z.cells.length; i++) { if (z.cells[i]._cellIndexS == cin) { cellHidden(z.cells[i], state); } } for (var i = 0; i < this.rowsBuffer.length; i++) { var c = this.rowsBuffer[i]; var cell = (c._childIndexes ? c.childNodes[c._childIndexes[cin]] : c.childNodes[cin]); cellHidden(cell, state); } this.setColumnSizes(); },
_fillRow : function(r, text) { if (this.editor) this.editStop(); for (var i = 0; i < r.childNodes.length; i++) { /** 加载数据时判断列是否隐藏 by 20140814 **/ cellHidden (r.childNodes[i], this.colHiddenArr[i]) if ((i < text.length) || (this.defVal[i])) { var ii = r.childNodes[i]._cellIndex; var val = text[ii]; var aeditor = this.cells4(r.childNodes[i]); if ((this.defVal[ii]) && ((val == "") || (typeof(val) == "undefined"))) val = this.defVal[ii]; if (aeditor) aeditor.setValue(val) } else { r.childNodes[i].innerHTML = " "; r.childNodes[i]._clearCell = true } }; return r },
调用API
setColumnHidden(ind, state)
-
ind - column index
-
state - true/false - hide/show column