📄 xtdbgrid.htc
字号:
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("calculateCol")){
vRowTemp += "<xsl:value-of select='" + visibleColsList(i).getAttribute("calculateCol") + "'/>";
}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'><font face='arial' size='1'><xsl:value-of select='position()'/></font></div></td>" + vFirstRow;
vOtherRow = vFixedCol + "'><font face='arial' size='1'>" + rowCnt + "</font></td>" + vOtherRow;
}
//
if(oCopyDataXML && oCopyDataXML.xml && oCopyDataXML.childNodes(0).childNodes.length <= 1){
vXslt += "<xsl:attribute name='bgcolor'>" + oddTRColor + "</xsl:attribute>" + vFirstRow + "</tr></xsl:when><xsl:otherwise><xsl:choose><xsl:when test='position() >" + getFirstPosition() + "'><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>";
}else{
vXslt += "<xsl:attribute name='bgcolor'>" + oddTRColor + "</xsl:attribute>" + vFirstRow + "</tr></xsl:when><xsl:otherwise><xsl:choose><xsl:when test='position() >=" + getFirstPosition() + " and position() <=" + 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;
//
tmpStr = oCopyDataXML.xml;
tmpStr = tmpStr.replace(/xmlns:fo=\"\"/g,"").replace(/1900-01-01/g,"");
oTBody.insertAdjacentHTML("afterBegin",__objGlobalCommonInst.transformXML(tmpStr,vXslt)); //插入转换后的HTML
//
oTBodyTable = oTBody.childNodes(0); //数据表格对象
oTBodyTable.onmousedown = 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.rows(0)) return(-1);
//
// try{
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 = 1; 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 宽度
collTitleCells(i).childNodes(0).style.pixelWidth = vMax; //title's cell宽度
}
/*
for(i = argNum; i < collDataCells.length; i++){//反向调整列宽
vMax = Math.max(collTitleCells(i).offsetWidth,collDataCells(i).offsetWidth); //取最大值
collDataCells(i).style.pixelWidth = vMax;
collTitleCells(i).style.pixelWidth = vMax;
}
*/
if(hasFixedCol == 1){
//alert();
//oTitleTable.rows(0).cells(0).childNodes(0).style.pixelWidth = oTBodyTable.rows(0).cells(0).style.pixelWidth + 14;
/*
vMax = Math.max(collTitleCells(0).offsetWidth,collDataCells(0).offsetWidth); //取最大值
collDataCells(0).childNodes(0).style.pixelWidth = vMax;
if(collTitleCells(0).style.pixelWidth == vMax){
collTitleCells(0).childNodes(0).style.pixelWidth = vMax - 2;
}else{
collTitleCells(0).childNodes(0).style.pixelWidth = vMax + 2;
}
*/
//alert();
//
collTitleCells(0).childNodes(0).style.pixelWidth = parseInt(collDataCells(0).childNodes(0).offsetWidth) + 2;
}
oTBody.scrollLeft = curScrollLeftStatus;//恢复滚动条位置
oTBody.scrollTop = curScrollTopStatus;
// }catch(e){
//错误丢弃
// alert("错误丢弃");
// }
}
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; //临时存储宽度
oTitle = element.document.createElement("<div class='phms_grid_oTitle'></div>"); // 创建标题div对象
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 class = 'phms_grid_oTitleInnerDiv'></div>");
oTitleInnerDiv.innerText = " ";
oTitleTD.appendChild(oTitleInnerDiv);
oTitleInnerDiv.style.left = 0;
}
//插入title table单元格
var visibleColsList = oTitleXML.selectNodes("/*/*[not(@visible = 'false')]"); //可以显示的列
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");//计算列计算公式
//////////////////////2004-03-03/////////////////////
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;//Table数据的XML对象
objDeletedXMLFragement = null;//用来保存已经删除了的行
oCopyDataXML = null;//Table数据的XML对象的拷贝
oPreviousRowXMLData = null;//双击时用来保存当前行XML数据对象
oTitleXML = null;//Title数据的XML对象
oControl = null;//控制面板容器对象
oTitle = null;//标题对象
oTitleTable = null;//标题table对象
oTitleTR = null;//标题行tr对象
oTitleTD = null;//标题cell对象
oTitleInnerDiv = null;//标题行 cell 中的 div 对象,用来撑开td
oTBody = null;//内容所在容器对象
oDataTable = null;//oTBody容器对象
oTBodyTable = null;//内容table对象
oTBodyTR = null;//内容tr对象
oTBodyTD = null;//内容cell对象
oFirstLineDiv = null;//第一行cell中的div对象,用来控制整个内容表的列宽
vTableCol = -1;
vTableRow = -1;//存储当前操作的cell
vPreviousCol = -1;
vPreviousRowForXML = -1;//存储上次操作的cell位置
vPreviousRow = -1;
vSelectionMode = "row";//选中方式(默认为单元格选中)
vPKColName = "";
allowResizeModle = true;//是否可以调整列宽
vMouseStart = 0; //鼠标初始位置,当前活动splitbar
bIsSelected = false;//单元格是否被选中
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -