dhtmlxGrid实现setColumnHidden

Java代码   收藏代码
  1. /** 设置TD隐藏或显示 by 20140814 **/  
  2. function cellHidden(cell, state) {  
  3.   if ((state) && (cell.style.display != "none")) {  
  4.     cell.style.display = "none";  
  5.   };  
  6.   if ((!state) && (cell.style.display == "none")) {  
  7.     cell.style.display = "";  
  8.   };  
  9. }  
  10.    

  

 

Js代码   收藏代码
  1. this.rowsBuffer = dhtmlxArray();  
  2. this.rowsCol = dhtmlxArray();  
  3. /** 列是否隐藏-数组 by 20140814 **/  
  4. this.colHiddenArr = {};  

 

 

Js代码   收藏代码
  1. this.setColumnSizes = function(gridWidth) {  
  2.   var summ = 0;  
  3.   var fcols = [];  
  4.   for (var i = 0; i < this._cCount; i++) {  
  5.     if ((this.initCellWidth[i] == "*") && !this._hrrar[i]) {  
  6.       this._awdth = false;  
  7.       fcols.push(i);  
  8.       continue  
  9.     };  
  10.     if (this.cellWidthType == '%') {  
  11.       if (typeof this.cellWidthPC[i] == "undefined")  
  12.         this.cellWidthPC[i] = this.initCellWidth[i];  
  13.       this.cellWidthPX[i] = Math.floor(gridWidth * this.cellWidthPC[i] / 100) || 0  
  14.     } else {  
  15.       if (typeof this.cellWidthPX[i] == "undefined")  
  16.         this.cellWidthPX[i] = this.initCellWidth[i]  
  17.     };  
  18.   
  19.     /** 计算列总宽度时,忽略隐藏列 by 20140814 **/  
  20.     if (!this._hrrar[i] && !this.colHiddenArr[i])  
  21.       summ += this.cellWidthPX[i] * 1  
  22.   };  
  23.   if (fcols.length) {  
  24.     var ms = Math.floor((gridWidth - summ) / fcols.length);  
  25.     if (ms < 0)  
  26.       ms = 1;  
  27.     for (var i = 0; i < fcols.length; i++) {  
  28.       var next = Math.max((this._drsclmW ? this._drsclmW[fcols[i]] : 0), ms)  
  29.       this.cellWidthPX[fcols[i]] = next;  
  30.       summ += next  
  31.     };  
  32.     this._setAutoResize()  
  33.   };  
  34.   this.obj.style.width = summ + "px";  
  35.   this.hdr.style.width = summ + "px";  
  36.   if (this.ftr)  
  37.     this.ftr.style.width = summ + "px";  
  38.   this.chngCellWidth();  
  39.   return summ  
  40. };  

 

 

Js代码   收藏代码
  1. this.chngCellWidth = function() {  
  2.   if ((_isOpera) && (this.ftr))  
  3.     this.ftr.width = this.objBox.scrollWidth + "px";  
  4.   var l = this._cCount;  
  5.   for (var i = 0; i < l; i++) {  
  6.     this.hdr.rows[0].cells[i].style.width = this.cellWidthPX[i] + "px";  
  7.     this.obj.rows[0].childNodes[i].style.width = this.cellWidthPX[i] + "px";  
  8.     if (this.ftr)  
  9.       this.ftr.rows[0].cells[i].style.width = this.cellWidthPX[i] + "px"  
  10.   
  11.     /** 针对列表中已有数据和列,判断隐藏|显示 by 20140814 **/  
  12.     cellHidden(this.hdr.rows[0].childNodes[i], this.colHiddenArr[i]);  
  13.     cellHidden(this.obj.rows[0].childNodes[i], this.colHiddenArr[i]);  
  14.     if (this.ftr)  
  15.       cellHidden(this.ftr.rows[0].cells[i], this.colHiddenArr[i]);  
  16.   
  17.   }  
  18. };  

 

 

Js代码   收藏代码
  1. setRowHidden : function (id, state) {},  
  2.   
  3.  /**  设置列隐藏|显示 by qiugq 20140814 **/  
  4.  setColumnHidden : function(cin, state) {  
  5.    this.colHiddenArr[cin] = state;  
  6.   
  7.    var z = this.hdr.rows[1];  
  8.    for (var i = 0; i < z.cells.length; i++) {  
  9.      if (z.cells[i]._cellIndexS == cin) {  
  10.        cellHidden(z.cells[i], state);  
  11.      }  
  12.    }  
  13.   
  14.    for (var i = 0; i < this.rowsBuffer.length; i++) {  
  15.      var c = this.rowsBuffer[i];  
  16.      var cell = (c._childIndexes ? c.childNodes[c._childIndexes[cin]] : c.childNodes[cin]);  
  17.      cellHidden(cell, state);  
  18.    }  
  19.   
  20.    this.setColumnSizes();  
  21.  },  

  

 

  

Java代码   收藏代码
  1. _fillRow : function(r, text) {  
  2.   if (this.editor)  
  3.     this.editStop();  
  4.   for (var i = 0; i < r.childNodes.length; i++) {  
  5.   
  6.     /** 加载数据时判断列是否隐藏 by 20140814 **/  
  7.     cellHidden (r.childNodes[i], this.colHiddenArr[i])  
  8.   
  9.     if ((i < text.length) || (this.defVal[i])) {  
  10.       var ii = r.childNodes[i]._cellIndex;  
  11.       var val = text[ii];  
  12.       var aeditor = this.cells4(r.childNodes[i]);  
  13.       if ((this.defVal[ii]) && ((val == "") || (typeof(val) == "undefined")))  
  14.         val = this.defVal[ii];  
  15.       if (aeditor)  
  16.         aeditor.setValue(val)  
  17.     } else {  
  18.       r.childNodes[i].innerHTML = "&nbsp;";  
  19.       r.childNodes[i]._clearCell = true  
  20.     }  
  21.   };  
  22.   return r  
  23. },  

 

 

 

 调用API

setColumnHidden(ind, state)

  • ind - column index
  • state - true/false - hide/show column
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值