📄 dbgrid.htc
字号:
if(objDataTable.rows[i].__rowid != ""){
objTempTD.innerHTML = "<input type='checkbox' idx='1'>";
objTempTD.firstChild.onclick = processCheckBoxClickEnent;
}
objDataTable.rows[i].cells[intFirstColIndex].insertAdjacentElement("beforeBegin",objTempTD);
}
}
////checkBox结束///////////////////////////////////////////////////////////////////////////////////////
if( booleanHasTotalLine ){//合计行
var objTRList = oTBody.all.tags("TR");
for( var i = (objTRList.length - 1); i > 0; i -- ){
if( objTRList[i].__rowid == ""){
objTRList[i].style.color = "black";
objTRList[i].style.fontWeight = "bold";
objTRList[i].style.background = "#eeeeee";
objTRList[i].height = "18";;
for( var j = 0; j < objTRList[i].children.length; j ++ ){
if( (booleanHasCheckBox && j == 2) || (!booleanHasCheckBox && j == 1) ){
objTRList[i].children[j].innerText = "合计";
}else{
if( objTRList[i].children[j].innerText == "" ){
objTRList[i].children[j].innerText = (isNaN(parseInt(objTRList[0].children[j].firstChild.innerText))) ? "" : 0;
}
}
}
break;
}
}
}
///////////////////////////
vReportDataTableInnerHTML = __objGlobalCommonInst.transformXML(tmpStr,vXslt);
oTBodyTable = oTBody.childNodes(0); //数据表格对象
oTBodyTable.onmousedown = clickTable;
oTBodyTable.ondblclick =dbclickCell;
if(oDataTable){
oTBody = oDataTable.insertAdjacentElement("beforeEnd",oTBody);
}
oTBody.onscroll = scrollIDL; //左右滚动事件绑定
adjustGridWidth(0);//协调表头和列的宽度一致
strRowIDS = "|" + arrCheckedRow.join("|");
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
}
//////////////////checkBox增加事件处理////////////
function processCheckBoxClickEnent(){
var objSrc = event.srcElement;
if(objSrc.tagName.toLowerCase() == "input"){
switch(objSrc.idx){
case "0":
var objCheckBoxList = oTBody.all.tags("input");
for( var i = 0; i < objCheckBoxList.length; i ++ ){
if( objSrc.checked ){
objCheckBoxList[i].checked = true;
setSelectRowBgcolor(objCheckBoxList[i].parentElement.parentElement,true);
}else{
objCheckBoxList[i].checked = false;
setSelectRowBgcolor(objCheckBoxList[i].parentElement.parentElement,false);
}
}
break;
case "1":
objSrc.checked ? setSelectRowBgcolor(objSrc.parentElement.parentElement,true) : setSelectRowBgcolor(objSrc.parentElement.parentElement,false);
break;
}
}
}
function setSelectRowBgcolor(objRow,setFlag){//用来设置行背景
if(objRow.tagName.toLowerCase() == "tr"){
for(var i = 1; i < objRow.cells.length; i ++ ){
if(setFlag){
objRow.cells[i].style.background = selectBgColor;
objRow.cells[i].style.color = selectForeColor;
}else{
objRow.cells[i].style.background = ( parseInt(objRow.rowIndex) % 2 == 0 ) ? evenTRColor : oddTRColor;
objRow.cells[i].style.color = "black";
}
}
}
}
function getSelectedOrderXMLRow(){//返回按titleXML顺序的r节点
if(booleanHasCheckBox){//多选处理
if(oCopyDataXML && oCopyDataXML.xml){
var strSelectedRowXML = "";
var objDataTable = oTBody.firstChild;
var objTempRNode = null;
for( var i = 0; i < objDataTable.rows.length; i ++ ){
if(objDataTable.rows[i].__rowid != "" && objDataTable.rows[i].cells[1].firstChild.checked){
objTempRNode = oCopyDataXML.selectSingleNode("//r[@__rowid = '" + objDataTable.rows[i].__rowid + "']");
strSelectedRowXML += objTempRNode.xml;
}
}
strSelectedRowXML = "<root>" + strSelectedRowXML + "</root>";
return __objGlobalCommonInst.inputXML(strSelectedRowXML);
}else{
return null;
}
}else{
var objR;
var aimXMLStr = "";
var strXSLT = '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="html"/><xsl:template match="//root"><xsl:element name="r"><xsl:for-each select="Col"><xsl:variable name="tmpName" select="@rpropname"/><xsl:attribute name="{$tmpName}"><xsl:value-of select="//root/r/@*[name()=$tmpName]"/></xsl:attribute></xsl:for-each></xsl:element></xsl:template></xsl:stylesheet>';
if(oCopyDataXML && oCopyDataXML.xml && tableRow !=-1){
objR = oCopyDataXML.selectSingleNode("//r[@__rowid='" + oTBodyTable.rows(tableRow).__rowid + "']");
aimXMLStr = "<root>" + oTitleXML.xml.replace("<root xmlns:fo=\"http://www.w3.org/1999/XSL/Format\">","").replace("<\/root>","").replace("<root>","") + objR.xml + "</root>";
return __objGlobalCommonInst.transformXMLToNode(aimXMLStr,strXSLT);
}else{
return null
}
}
}
///////checkBox增加事件处理结束/////////////////////////////////////////////////////
function adjustGridWidth(argNum){ //调整title和data的宽度一致
var vMax; //取title table中较大的div的长度
var collTitleCells;
var collDataCells;
if(!oTBodyTable.rows(0)) return(-1);
//
collTitleCells = oTitleTable.rows(0).cells;
collDataCells = oTBodyTable.rows(0).cells;
oTitleTable.style.pixelWidth = 1; //让表格收缩到最小才能利用其中的div撑大
oTBodyTable.style.pixelWidth = 1;
/*
oTitleTable.rows(0).cells(0).childNodes(0).style.pixelWidth = 1;
*/
for(i = 0; i < collDataCells.length; i++){ //table照着title变化
if(i == 0){
collDataCells(i).childNodes(0).style.pixelWidth = 30;
collTitleCells(i).childNodes(0).style.pixelWidth = 30;
}else{
vMax = Math.max(collTitleCells(i).childNodes(0).offsetWidth,collDataCells(i).offsetWidth); //取最大值
collDataCells(i).childNodes(0).style.pixelWidth = vMax; //table's cell 宽度
collTitleCells(i).childNodes(0).style.pixelWidth = vMax; //title's cell宽度
}
}
if(hasFixedCol == 1){
collTitleCells(0).childNodes(0).style.pixelWidth = parseInt(collDataCells(0).childNodes(0).offsetWidth);
}
oTBody.scrollLeft = curScrollLeftStatus;//恢复滚动条位置
oTBody.scrollTop = curScrollTopStatus;
}
function scrollIDL(){//左右滚动
//
if(funVerifyInputWhenBlur() == -1){
return(-1);
}
oTitleTable.style.marginLeft = - oTBody.scrollLeft;
curScrollLeftStatus = oTBody.scrollLeft;
curScrollTopStatus = oTBody.scrollTop;
hideInput();
}
function createTitle(){ //生成DBGrid组件标题行,并用XML数据填充
var vWidthTemp; //临时存储宽度
intColCount = 0;//初始化列数
oTitle = element.document.createElement("<div class='phms_grid_oTitle'></div>"); // 创建标题div对象
oTitle.oncontextmenu = function(){event.returnValue = false;};
if(oTitleTable) oTitleTable.removeNode(true); // 删除原有标题
oTitleTable = null;
oTitleTable = element.document.createElement("<table style='font-size:9pt;' border=0 cellspacing=1 cellpadding=0></table>");
oTitleTable.bgcolor = dataBgColor;
oTitleTR = oTitleTable.insertRow();
oTitleTR.height = 20;
oTitleTR.bgColor = titleBgColor;
oTitleTR.style.color = titleForeColor;
var tmpWidth;
if(hasFixedCol == 1){ //插入固定列
oTitleTD = oTitleTR.insertCell();
oTitleInnerDiv = element.document.createElement("<div/>");
//oTitleInnerDiv.style.width = 40;
oTitleTD.appendChild(oTitleInnerDiv);
oTitleInnerDiv.style.left = 0;
}
//插入title table单元格
var visibleColsList = oTitleXML.selectNodes("/*/*[not(@visible = 'false')]"); //可以显示的列
intColCount = (hasFixedCol == 1) ? (visibleColsList.length + 1) : visibleColsList.length;
for(var i = 0; i < visibleColsList.length; i++){
oTitleTD = oTitleTR.insertCell();
oTitleTD.noWrap = "noWrap";
oTitleInnerDiv = element.document.createElement("<div class='phms_grid_oTitleInnerDiv'></div>"); //创建用于撑宽TD的div
if(hasFixedCol == 0) oTitleInnerDiv.style.left = 1;//调整标题与列偏差
tmpWidth = visibleColsList(i).getAttribute("width") - 4;
oTitleInnerDiv.style.pixelWidth = tmpWidth; //设置宽度
oTitleInnerDiv.MinWidth = visibleColsList(i).getAttribute("minwidth"); //设置最小宽度
if(oTitleInnerDiv.MinWidth == null) oTitleInnerDiv.MinWidth = tmpWidth;
oTitleInnerDiv.MaxWidth = visibleColsList(i).getAttribute("maxwidth"); //设置最大宽度
if(oTitleInnerDiv.MaxWidth == null) oTitleInnerDiv.MaxWidth = tmpWidth;
oTitleInnerDiv.rpropname = visibleColsList(i).getAttribute("rpropname"); //设置RPropName属性
oTitleInnerDiv.innerText = visibleColsList(i).getAttribute("caption"); //表字段的标题
oTitleInnerDiv.EditType = visibleColsList(i).getAttribute("EditType"); //编辑模式
oTitleInnerDiv.DataType = visibleColsList(i).getAttribute("DataType"); //数据类型
oTitleInnerDiv.allowSort = visibleColsList(i).getAttribute("allowSort"); //是否允许排序
oTitleInnerDiv.maxlength = visibleColsList(i).getAttribute("maxlength"); //该列允许接受的最长字符长度
oTitleInnerDiv.calculateCol = visibleColsList(i).getAttribute("calculateCol");//计算列计算公式
oTitleInnerDiv.valueCol = visibleColsList(i).getAttribute("valueCol");
oTitleInnerDiv.textCol = visibleColsList(i).getAttribute("textCol");
oTitleInnerDiv.onmousedown = clickTitle;
oTitleInnerDiv.style.top = 2;
oTitleTD.appendChild(oTitleInnerDiv);
if(allowResizeModle.toString() == "true" && i != 0) createSplitBar(oTitleInnerDiv); //除第一行外都生成SplitBar
}
//生成最后一个拖动span
oTitleTD = oTitleTR.insertCell();
oTitleInnerDiv = element.document.createElement("<div class='phms_grid_oTitleInnerDiv'></div>");
oTitleInnerDiv.innerText = " ";//遮盖滚动条留出的空白
oTitleTD.appendChild(oTitleInnerDiv);
createSplitBar(oTitleInnerDiv);
oTitleTable = oTitle.appendChild(oTitleTable); //标题表格对象
oTitle = element.appendChild(oTitle);
if(hasTitle.toString() == "false") oTitle.style.display = "none"; //是否有表头
}
function refresh(){//DBGrid组件位置、样式初始化
with(element){//element定位
style.top = vTop;
style.left = vLeft;
style.width = vWidth;
style.height = vHeight;
style.borderColor = borderColor;
onkeydown = keydownTBodyTable;
onmousedown = lostFocus;
}
if(oTBody){
with(oTBody){ //面板
style.width = vWidth;
style.height = vHeight;
}
}
if(oTBody && oTitle){ //设置table div
with(oTBody){
style.pixelHeight = vHeight - oTitle.offsetHeight;
}
with(oTitle){
style.pixelWidth = vWidth;
}
}
}//End of refresh
function clear(){//清空所有对象
var objLeafElement;
//////////////////////////////////////////////////////////
oDataXML = null;
objDeletedXMLFragement = null;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -