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

📄 calculategrid.htc

📁 HTC,demo WEB用于。 超大型
💻 HTC
📖 第 1 页 / 共 5 页
字号:
          if(i == 3) return;
          if(objSrc.rowIndex == 2) return;
          selected(objSrc,true); //选中当前行
          objScrollTrack = objSrc;
        }

        function cancelSelectScrollTrack(){ //取消鼠标跟随中的前次选择
          if(objScrollTrack) selected(objScrollTrack,false); //取消前次选中
        }

        function selected(objSrc,bIsSelected){ //选中某一对象即改变其背景和前景色,参数为对象、是否选中标志
          if(bIsSelected){
            with(objSrc.runtimeStyle){
              color = "#ffffff";
              backgroundColor = "#000000";
            }
          }
          else{
            with(objSrc.runtimeStyle){
              color = "";
              backgroundColor = "";
            }
          }
        }   

        function clickTable(){//点击DBGrid组件cell时处理事件

          var oSrc,i;
          var vRowTemp;
          var n;
          var objParentTR;
          var boolInArr = false;

          selectTable(false); //取消前次的table选择
          oSrc = window.event.srcElement;
          
          if(oSrc.tagName == "INPUT" && oSrc.type == "checkbox"){
          
            objParentTR = oSrc;
            for(var i=0;i < 4;i++){
              if(objParentTR.tagName == "TR"){
                break;
              }else{
                objParentTR = objParentTR.parentElement;
              }
            }
            if(i==4) return;//没有找到相应的行            
            
            if(oSrc.checked == true){//如果checkBox的状态为选中
              n = arrCheckedRow.length;
              for(var i = 0; i < n; i++){//判断该checkBox所在行的__rowid是否已经被加到了arrCheckRow数组中
                if(arrCheckedRow[i] == objParentTR.__rowid){
                  boolInArr = true;
                  break;
                }//End of if
              }//End of for 
              //alert("true add " + boolInArr);
              if(!boolInArr)//没有加进去  
                arrCheckedRow.push(objParentTR.__rowid);                        
            }else{//如果checkBox的状态为未选中
              n = arrCheckedRow.length;
              for(var i = 0; i < n; i++){
                if(arrCheckedRow[i] == objParentTR.__rowid){//将该行的__rowid从arrcheckRow数组中删除                
                  boolInArr = true;
                  arrCheckedRow.splice(i,1);
                  break;
                }//End of if
              }//End of for           
            }
          }//End of if
          
          for(i = 0; i < 2; i++){ //取得点击的td对象
            if(oSrc.tagName.toLowerCase() == "td") break;
            oSrc = oSrc.parentElement;
          }
          if(i == 2) return; //说明没有找到td元素,返回
          
          vTableRow = oSrc.parentElement.rowIndex;//行
          vTableCol = oSrc.cellIndex;//列
          //alert("tableRow=" + tableRow + "\ntableCol=" + tableCol);
          if(vSelectionMode == "row" && vTableCol < 0) vTableCol = 1;
          selectTable(true); //选择当前点击的cell或者row  
          showRC();
          evtClickCell.fire();
          //window.status = "所有选中的checkBox数量为:" + arrCheckedRow.length;
      }     
      

      function showRC(){//显示当前cell的行列坐标
        if(hasController=="true" && oControl!=null){
            var r = parseInt(tableRow) + 1;
            var c = parseInt(tableCol) + 1;
            if(r>=0 && c>=0){
              oControl.curRow.value = "[行:" + r;
              oControl.curCol.value = "列:" + c + "]";
            }
        }
        hideInput();
      }

      function selectTable(bIsSelected){ //选择或者取消由 tableCol 和 tableRow 指定的单元格或其所在的表行(包括fixed col和对应的title cell)
        try{
          var collCells;
          if(vTableRow < 0 || vTableCol < 0) return; //如果尚未在表格中使用鼠标选择则不能进行 key选择

            collCells = oTBodyTable.rows(vTableRow).cells;
            if(vSelectionMode == "cell"){ //单元格选择
              selected(collCells(vTableCol),bIsSelected);
            }else{ //行选
              for(i = 0; i < collCells.length; i++){
                selected(collCells(i),bIsSelected);
              }
            }
        }catch(e){}
      }

      function selected(objSrc,bIsSelected){ //选中某一对象即改变其背景和前景色,参数为对象、是否选中标志
        try{
          if(bIsSelected){  
              objSrc.runtimeStyle.color  = selectForeColor;
              objSrc.runtimeStyle.backgroundColor = selectBgColor;
          }else{
            with(objSrc.runtimeStyle){
              color = "";
              backgroundColor = "";
            }
          }
        }catch(e){
          //错误丢弃
        }
      }

        function clickTitle(){ //点击标题行

          var vAllowSort = oTitleTable.rows(0).cells(event.srcElement.parentElement.cellIndex).children(0).getAttribute("AllowSort");
          if(vAllowSort=="false") return;//该列不允许排序
          
          var oSrc = null;
          oSrc = window.event.srcElement;    
          for(var i = 0; i < 3; i++){
            if(oSrc.tagName.toLowerCase() == "div" && oSrc.getAttribute("rpropName")) break;
            oSrc = oSrc.parentElement;
          }

          if(i == 3) return;//没有找到div

          var vOrder = null;//排序规则          
          
          if(oSrc == oSortBtn.parentElement){//如果点击的是同一列
            if(oSortBtn.children(0).style.flip == "y"){
              oSortBtn.children(0).style.flip = "";
              vOrder = "ascending";
            }else{
              oSortBtn.children(0).style.flip = "y";
              vOrder = "descending";
            }
          }else{//点击的不是同一列
            oSortBtn.children(0).style.flip = "";
            oSortBtn = oSrc.appendChild(oSortBtn);
            vOrder = "ascending";
          }       

          sort(oSrc.getAttribute("rpropName"),vOrder); //开始排序   

        }

        function sort(colName,order){ //对指定列按指点规则进行排序
          var vXslt;

          vXslt = "<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:output method='xml' omit-xml-declaration='no' encoding='gb2312' version='1.0' indent='yes'/><xsl:template match='/'><root><xsl:for-each select='*/*'><xsl:sort select='@" + colName + "' order='" + order + "'/><xsl:copy-of select='.'/><xsl:copy-of select='@*'/></xsl:for-each></root></xsl:template></xsl:stylesheet>";
          oCopyDataXML = inputXML(__objGlobalCommonInst.transformXML(oCopyDataXML,vXslt)); //xml依据排序转换
          fillInTable(); //填充表格
          /*
          if(hasPageFooter == "true")
             viewPageFooter(); 
             */
        }


        function fillInTable(){ //生成DBGrid组件数据表,用XML数据填充

          var oXSLT = null;//XSLT对象
          var vXslt = null;//xslt字符串
          var vFirstRow = "";//第一行xslt
          var vOtherRow = "";//其它行xslt
          var vRowTemp = ""; //临时xslt
          var vFixedCol = "";
          var strRowIDS = "";//用来保存通过checkBox选中行的__rowid所组成的字符串
          
          if(oTitleXML == null) return;
          
          if(oTBody) oTBody.removeNode(true);//删除原有数据表容器
          oTBody = null;

          oTBody = window.document.createElement("<div class='phms_grid_oTBody'></div>");         

          if(oTBodyTable) oTBodyTable.removeNode(true); //删除原有表格
          oTBodyTable = null;
          refresh();

          var visibleColsList = oTitleXML.selectNodes("/*/*[not(@visible = 'false')]"); 
          //构造xslt    
          vXslt = "<xsl:stylesheet version = '1.0' xmlns:xsl = 'http://www.w3.org/1999/XSL/Transform'><xsl:output method = 'html'/><xsl:template match = '/'><table class='phms_grid_oTBodyTable' bgcolor='" 
          + dataBgColor + "' border = '0'  cellspacing = '1' cellpadding = '0'><xsl:for-each select = '*/*'><xsl:choose><xsl:when test='position() = " + getFirstPosition() + "'><tr bgcolor='" 
          + dataBgColor + "' height='18'><xsl:attribute name='__rowid'><xsl:value-of select='@__rowid'/></xsl:attribute>";

          for(var i = 0; i < visibleColsList.length; i++){ //获取列值
            var rowCnt = "<xsl:value-of select='position()'/>";//行位置         
  
              if(visibleColsList(i).getAttribute("EditType")=="c"){//如果该列为checkBox列
                  vRowTemp = "<input id='ichk' type='checkbox' class='phms_r_c'></input>";                
              }else{
                  vRowTemp = "";
              }//End of if edittype = "c"
              
             // if(visibleColsList(i).getAttribute("formula")){
                //vRowTemp += "<xsl:value-of select='" + visibleColsList(i).getAttribute("formula") + "'/>";                     
              //}else{
                vRowTemp += "<xsl:value-of select='@" + visibleColsList(i).getAttribute("rpropName") + "'/>";                     
             // }
              
              vFirstRow += "<td align='center'>" + "<div class='phms_grid_oFirstLineDiv'>" + vRowTemp + "</div></td>";
              vOtherRow += "<td align='center'>" + vRowTemp + "</td>";
          }

          if(parseInt(hasFixedCol) == 1){ //生成fixed col xslt
            vFixedCol = "<td class='phms_grid_index' align='" +  fixedColAlign + "' style='color:" + fixedColForeColor + "; background:" + fixedColBGColor + ";";
            vFirstRow = vFixedCol + "'><div class = 'phms_grid_indexDiv'><xsl:value-of select='position()'/></div></td>" + vFirstRow;
            vOtherRow = vFixedCol + "'><font face='arial' size='1'>" +  rowCnt + "</font></td>" + vOtherRow;
          }

          vXslt += "<xsl:attribute name='bgcolor'>" + oddTRColor + "</xsl:attribute>" + vFirstRow + "</tr></xsl:when><xsl:otherwise><xsl:choose><xsl:when test='position() &gt;=" + getFirstPosition() + " and position() &lt;=" + getLastPosition() + "'><tr><xsl:attribute name='__rowid'><xsl:value-of select='@__rowid'/></xsl:attribute><xsl:if test='position() mod 2 = 0'><xsl:attribute name='bgcolor'>" 
          + evenTRColor + "</xsl:attribute></xsl:if><xsl:if test='position() mod 2 != 0'><xsl:attribute name='bgcolor'>" + oddTRColor + "</xsl:attribute></xsl:if>" + vOtherRow +  "</tr></xsl:when></xsl:choose></xsl:otherwise></xsl:choose></xsl:for-each></table></xsl:template></xsl:stylesheet>";

        
        
          if(oCopyDataXML == null) return; 
          
          oTBody.insertAdjacentHTML("afterBegin",__objGlobalCommonInst.transformXML(oCopyDataXML,vXslt)); //插入转换后的HTML
          //
          oTBodyTable = oTBody.childNodes(0); //数据表格对象
          oTBodyTable.onclick = clickTable;
          oTBodyTable.ondblclick =dbclickCell;

          oTBody = oDataTable.insertAdjacentElement("beforeEnd",oTBody); 
          oTBody.onscroll = scrollIDL; //左右滚动事件绑定           
          adjustGridWidth(0);//协调表头和列的宽度一致     
          //
          strRowIDS = "|" + arrCheckedRow.join("|");
          //window.prompt("",strRowIDS);

          if(strRowIDS != ""){//如果有选中的行          
          
            for(var i=0; i<oTBodyTable.rows.length; i++){
              if((strRowIDS.indexOf("|" + oTBodyTable.rows[i].__rowid ) > 0) || (strRowIDS.indexOf(oTBodyTable.rows[i].__rowid + "|") > 0)){
                oTBodyTable.rows[i].all("ichk").checked = true;                
              }           
            }//End of for
            
          }//End of if        
      
      }   
                

      function adjustGridWidth(argNum){ //调整title和data的宽度一致
        var vMax; //取title table中较大的div的长度
        var collTitleCells;
        var collDataCells;
        
        if(!oTBodyTable) return(-1);
        
        try{   
          collTitleCells = oTitleTable.rows(0).cells;
          collDataCells = oTBodyTable.rows(0).cells;

          oTitleTable.style.pixelWidth = 1; //让表格收缩到最小才能利用其中的div撑大
          oTBodyTable.style.pixelWidth = 1;
        
          for(i = argNum; i < collDataCells.length; i++){ //table照着title变化
            vMax = Math.max(collTitleCells(i).childNodes(0).offsetWidth,collDataCells(i).offsetWidth); //取最大值
            collDataCells(i).childNodes(0).style.pixelWidth = vMax; //table's cell 宽度

⌨️ 快捷键说明

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