📄 flexgrid.htc
字号:
//将跨行数量转换为rowSpan属性
for(i = 0; i < oTBodyTable.rows.length; i++){
for(j = 0; j<arrMCol.length; j++){
if(oTBodyTable.rows[i].cells[arrMCol[j]].rowSp && oTBodyTable.rows[i].cells[arrMCol[j]].rowSp > 1){
oTBodyTable.rows[i].cells[arrMCol[j]].rowSpan = oTBodyTable.rows[i].cells[arrMCol[j]].rowSp;
}
}
}
//将bDelete = 'y'的单元格删除
for(i = 0;i < oTBodyTable.rows.length;i++){
for(j = oTBodyTable.rows[i].cells.length; j >= 0 ; j--){
//for(var x = 0; x < arrMCol.length; x++){
try{
if(oTBodyTable.rows[i].cells[j].bDelete && oTBodyTable.rows[i].cells[j].bDelete == "y"){
oTBodyTable.rows[i].deleteCell(j);
//j++;
}//End of if
}catch(e){
//j++;
}//End of Try
//}//End of x
}//End of for j
}//End of for i
//debugger;
}//End of if
}
/*
function mergeRow(){ //限制行合并,行数不允许改变,合并行上的列
var i,j,m;
//设置限制行合并的删除标志并计算跨列数量
for(i = 0; i < oTBodyTable.rows.length; i++){
for(j = vFixedCols; j < oTBodyTable.rows[i].cells.length - 1; j++){ //取出一个cell,循环到倒数第二列,因为最后一列不需要向后寻找相同值的列了
for(m = j+1; m < oTBodyTable.rows[i].cells.length; m++){ //取出在同一行的其后的一个cell
if(oTBodyTable.rows[i].cells[j].innerText == oTBodyTable.rows[i].cells[m].innerText){ //看两个cell内容是否相等
oTBodyTable.rows[i].cells[j].colSp = parseInt(oTBodyTable.rows[i].cells[j].colSp)+1; //相等则修改前一个单元格的colSp属性,表示该单元格将跨的列数
oTBodyTable.rows[i].cells[m].bDelete = "y"; //并将后一个单元格作上删除标记,在后面将删除掉
}else break; //一旦出现的单元格的内容与最初比较的前一个单元格内容不相符则不再比较,退出最里面的循环
}
j = m-1; //接着从不相等的单元格开始下一轮比较( j 的循环,到上面j++将使得从不相等的单元格开始)
}
}
//将以上步骤中计算的跨列数量转换为cell的colSpan
for(i = 0; i < oTBodyTable.rows.length; i++){ //行限制合并中的设置修改(限制行合并特有)
for(j = vFixedCols; j < oTBodyTable.rows[i].cells.length; j++){
if(oTBodyTable.rows[i].cells[j].colSp > 1){
oTBodyTable.rows[i].cells[j].colSpan = oTBodyTable.rows[i].cells[j].colSp;
}
}
}
//删除被标记为bDelete == 'y'的 cell
for(i = 0 ;i<oTBodyTable.rows.length;i++){ //行限制合并中的设置修改(限制行合并特有)
for(j = vFixedCols; j < oTBodyTable.rows[i].cells.length; j++){
if(oTBodyTable.rows[i].cells[j].bDelete == "y"){
oTBodyTable.rows[i].deleteCell(j);
j--;
}
}
}
}
*/
/////////////////////////////////////////////////////////////////////////////////////
function adjustGridWidth(argNum){ //调整title和data的宽度一致
var vWidthMax; //取title table中较大的div的长度
var collTitleCells;
var collDataCells;
if(!oTBodyTable) return(-1);
try{
collTitleCells = oTitleTable.all.tags("DIV");
collDataCells = oTBodyTable.rows(0).cells;
oTitleTable.style.pixelWidth = 1; //让表格收缩到最小才能利用其中的div撑大
oTBodyTable.style.pixelWidth = 1;
for(i = 0; i < arrSortDiv.length; i++){ //table照着title变化
if(oTitleTable.all(arrSortDiv[i].id).parentElement.offsetWidth > oTBodyTable.all(arrSortDiv[i].id).parentElement.offsetWidth){
vWidthMax = oTitleTable.all(arrSortDiv[i].id).parentElement.offsetWidth;
oTBodyTable.all(arrSortDiv[i].id).style.pixelWidth = vWidthMax; //title's cell宽度
oTBodyTable.all(arrSortDiv[i].id).style.pixelWidth = oTBodyTable.all(arrSortDiv[i].id).parentElement.offsetWidth;
}else{
vWidthMax = oTitleTable.all(arrSortDiv[i].id).parentElement.offsetWidth;
oTBodyTable.all(arrSortDiv[i].id).style.pixelWidth = vWidthMax; //title's cell宽度
oTBodyTable.all(arrSortDiv[i].id).style.pixelWidth = oTBodyTable.all(arrSortDiv[i].id).parentElement.offsetWidth;
}
}
for(i = argNum; i < arrSortDiv.length; i++){ //title照着table变化
if(oTitleTable.all(arrSortDiv[i].id).parentElement.offsetWidth > oTBodyTable.all(arrSortDiv[i].id).parentElement.offsetWidth){
vWidthMax = oTBodyTable.all(arrSortDiv[i].id).offsetWidth;
oTitleTable.all(arrSortDiv[i].id).style.pixelWidth = vWidthMax - 6; //title's cell宽度
}else{
vWidthMax = oTBodyTable.all(arrSortDiv[i].id).offsetWidth;
oTitleTable.all(arrSortDiv[i].id).style.pixelWidth = vWidthMax - 6; //title's cell宽度
}
}
oTitleTable.all(arrSortDiv[0].id).style.pixelWidth = collDataCells(0).offsetWidth - 6;
oTBody.scrollLeft = curScrollLeftStatus;//恢复滚动条位置
oTBody.scrollTop = curScrollTopStatus;
}catch(e){
}
}
function scrollIDL(){//左右滚动
oTitleTable.style.marginLeft = - oTBody.scrollLeft;
curScrollLeftStatus = oTBody.scrollLeft;
curScrollTopStatus = oTBody.scrollTop;
}
function createTitle(){ //生成FlexGrid组件标题行,并用XML数据填充
var vWidthTemp; //临时存储宽度
var varvTitleXSLT;//标题转换的XSLT
var leafNumber = 0;
var oCopyTitleXML = null;
var vCopyTitleXSLT;//
oTitle = window.document.createElement("<div class='phms_flexGrid_oTitle'></div>"); // 创建标题div对象
oTitle.oncontextmenu = function(){event.returnValue = false;};
if(oTitleTable) oTitleTable.removeNode(true);// 删除原有标题
oTitleTable = null;
if(hasFixedCol == 1){ //有索引列
varvTitleXSLT = "<?xml version=\"1.0\" encoding=\"gb2312\"?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"><xsl:output method=\"xml\" version=\"1.0\" encoding=\"gb2312\" indent=\"no\" omit-xml-declaration=\"yes\"/><xsl:variable name=\"depth\" select=\"count(/*//*[count(ancestor::*)>count(preceding::*/ancestor::*)])\"/><xsl:template match=\"/\"><table bgcolor=\"#000000\" cellspacing=\"1\" cellpadding=\"3\" border=\"0\" class=\"phms_flexGrid_oTitle\" vhinfo=\"thead\"><colgroup><xsl:for-each select=\"/*//*[not(@visible='false') and count(*) = 0]\"><col style=\"width:{@width}\"/></xsl:for-each></colgroup><xsl:for-each select=\"/*//*[count(ancestor::*) > count(preceding::*/ancestor::*)]\"><tr><xsl:if test='position()=1'><td><xsl:attribute name=\"bgcolor\">#CAEAFF</xsl:attribute><xsl:attribute name='rowspan'><xsl:value-of select='$depth'/></xsl:attribute><xsl:attribute name='dataType'><xsl:value-of select='@datatype'/></xsl:attribute><div class=\"phms_flexGrid_oTitleIndexDiv\"><xsl:attribute name=\"id\">" + strConstIndexColID + "</xsl:attribute></div></td></xsl:if><xsl:variable name=\"parentNum\" select=\"count(ancestor::*)\"/><xsl:for-each select=\"//*[not(@visible='false') and count(ancestor::*) = $parentNum]\"><xsl:apply-templates select=\".\"/></xsl:for-each></tr></xsl:for-each></table></xsl:template><xsl:template match=\"Col\"><td><xsl:attribute name=\"bgcolor\">#CAEAFF</xsl:attribute><xsl:attribute name=\"align\">center</xsl:attribute><xsl:choose><xsl:when test=\"count(*) = 0 or (count(*)!=0 and name(*)='r')\"><xsl:attribute name=\"rowspan\"><xsl:value-of select=\"$depth - count(ancestor::*) + 1\"/></xsl:attribute><xsl:attribute name='dataType'><xsl:value-of select='@datatype'/></xsl:attribute><div class=\"phms_flexGrid_oTitleInnerDiv\" id=\"{generate-id()}\"><xsl:attribute name=\"style\">width:<xsl:value-of select=\"@width\"/></xsl:attribute><xsl:attribute name=\"dataType\"><xsl:value-of select=\"@datatype\"/></xsl:attribute><xsl:copy-of select=\"@allowSort\"/><xsl:copy-of select=\"@maxwidth\"/><xsl:copy-of select=\"@minwidth\"/><xsl:copy-of select=\"@edittype\"/><xsl:copy-of select=\"@rpropname\"/><xsl:copy-of select=\"@valueCol\"/><xsl:copy-of select=\"@textCol\"/><xsl:value-of select=\"@caption\"/></div></xsl:when><xsl:otherwise><xsl:attribute name=\"colspan\"><xsl:value-of select=\"count(.//*[count(*) = 0])\"/></xsl:attribute><xsl:value-of select=\"@caption\"/></xsl:otherwise></xsl:choose><xsl:copy-of select=\"@maxwidth\"/><xsl:copy-of select=\"@minwidth\"/><xsl:copy-of select=\"@datatype\"/><xsl:copy-of select=\"@rpropname\"/><xsl:attribute name=\"curcol\"><xsl:value-of select=\"count(preceding::*[not(@visible='false') and count(*) = 0])\"/></xsl:attribute></td></xsl:template></xsl:stylesheet>";
}else{//无索引列
varvTitleXSLT = "<?xml version=\"1.0\" encoding=\"gb2312\"?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"><xsl:output method=\"xml\" version=\"1.0\" encoding=\"gb2312\" indent=\"no\" omit-xml-declaration=\"yes\"/><xsl:variable name=\"depth\" select=\"count(/*//*[count(ancestor::*)>count(preceding::*/ancestor::*)])\"/><xsl:template match=\"/\"><table bgcolor=\"#000000\" cellspacing=\"1\" cellpadding=\"3\" border=\"0\" class=\"phms_flexGrid_oTitle\"><colgroup><xsl:for-each select=\"/*//*[not(@visible='false') and count(*) = 0]\"><col style=\"width:{@width}\"/></xsl:for-each></colgroup><xsl:for-each select=\"/*//*[count(ancestor::*) > count(preceding::*/ancestor::*)]\"><tr><xsl:variable name=\"parentNum\" select=\"count(ancestor::*)\"/><xsl:for-each select=\"//*[not(@visible='false') and count(ancestor::*) = $parentNum]\"><xsl:apply-templates select=\".\"/></xsl:for-each></tr></xsl:for-each></table></xsl:template><xsl:template match=\"Col\"><td><xsl:attribute name='dataType'><xsl:value-of select='@dataType'/></xsl:attribute><xsl:attribute name=\"bgcolor\">#CAEAFF</xsl:attribute><xsl:choose><xsl:when test=\"count(*) = 0 or (count(*)!=0 and name(*)='r')\"><xsl:attribute name=\"rowspan\"><xsl:value-of select=\"$depth - count(ancestor::*) + 1\"/></xsl:attribute><div class=\"phms_flexGrid_oTitleInnerDiv\" id=\"{generate-id()}\"><xsl:attribute name=\"style\">width:<xsl:value-of select=\"@width\"/></xsl:attribute><xsl:copy-of select=\"@maxwidth\"/><xsl:copy-of select=\"@minwidth\"/><xsl:copy-of select=\"@edittype\"/><xsl:copy-of select=\"@datatype\"/><xsl:copy-of select=\"@rpropname\"/><xsl:value-of select=\"@caption\"/></div></xsl:when><xsl:otherwise><xsl:attribute name=\"colspan\"><xsl:value-of select=\"count(.//*[count(*) = 0])\"/></xsl:attribute><xsl:value-of select=\"@caption\"/></xsl:otherwise></xsl:choose><xsl:copy-of select=\"@allowSort\"/><xsl:copy-of select=\"@maxwidth\"/><xsl:copy-of select=\"@minwidth\"/><xsl:copy-of select=\"@datatype\"/><xsl:copy-of select=\"@rpropname\"/><xsl:copy-of select=\"@valueCol\"/><xsl:copy-of select=\"@textCol\"/><xsl:attribute name=\"curcol\"><xsl:value-of select=\"count(preceding::*[not(@visible='false') and count(*) = 0])\"/></xsl:attribute></td> </xsl:template></xsl:stylesheet>";
}
vCopyTitleXSLT = "<xsl:stylesheet version=\"1.0\" xmlns:xsl= \"http://www.w3.org/1999/XSL/Transform\" xmlns:fo=\"http://www.w3.org/1999/XSL/Format\"><xsl:output method=\"xml\" omit-xml-declaration=\"no\" encoding=\"GB2312\" version=\"1.0\" indent=\"yes\"/><xsl:template match = \"//root\"><xsl:copy><xsl:apply-templates select=\"Col\"/></xsl:copy></xsl:template><xsl:template match=\"Col\"><xsl:copy><xsl:for-each select=\"@*\"><xsl:attribute name=\"{name()}\"><xsl:value-of select=\".\"/></xsl:attribute></xsl:for-each></xsl:copy></xsl:template></xsl:stylesheet>";
///////////////////////
strTitleTableInnerXML = __objGlobalCommonInst.transformXML(oTitleXML,varvTitleXSLT);
//window.prompt("",__objGlobalCommonInst.transformXML(oTitleXML,varvTitleXSLT));
vReportTitleTableInnerHTML = __objGlobalCommonInst.transformXML(oTitleXML,varvTitleXSLT);
oTitle.insertAdjacentHTML("afterBegin",strTitleTableInnerXML); //插入转换后的HTML
oTitleTable = oTitle.childNodes(0);
for(var i =0; i < oTitleTable.all.length; i++){
if(oTitleTable.all(i).tagName == "DIV"){
oTitleInnerDiv = oTitleTable.all(i);
oTitleInnerDiv.onmousedown = clickTitle;
oTitleInnerDiv.parentElement.onmousedown = clickTitle;
oTitleInnerDiv.leafNumber = leafNumber;
leafNumber = leafNumber + 1;
if(allowResizeModle.toString() == "true" && i!= 0) createSplitBar(oTitleInnerDiv); //除第一行外都生成SplitBar
}
}
oTitle = element.appendChild(oTitle);
function funCompare(objA, objB){
return(parseInt(objA.left)-parseInt(objB.left));
}
function ArrItem(intIndex,strID, intLeft, stRrpropname, strEditType, strDataType){
this.index = intIndex;
this.id = strID;
this.left = intLeft;
this.rpropname = stRrpropname;
this.EditType = strEditType;
this.dataType = strDataType;
}
for(var i = 0; i < oTitleTable.all.tags("DIV").length; i++){
arrSortDiv[i] = new ArrItem(i,oTitleTable.all.tags("DIV")(i).id, oTitleTable.all.tags("DIV")(i).offsetLeft, oTitleTable.all.tags("DIV")(i).rpropname, oTitleTable.all.tags("DIV")(i).EditType, oTitleTable.all.tags("DIV")(i).dataType);
}
arrSortDiv.sort(funCompare);
if(hasTitle.toString() == "false") oTitle.style.display = "none"; //是否有表头
}
function refresh(){//FlexGrid组件位置、样式初始化
with(element){//element定位
style.top = top;
style.left = left;
style.width = width;
style.height = height;
style.borderColor = borderColor;
onkeydown = keydownTBodyTable;
onmousedown = lostFocus;
}
if(oTBody){
with(oTBody){ //面板
style.width = width;
style.height = height;
}
}
if(oTBody && oTitle){ //设置table div
with(oTitle){
style.pixelWidth = width;
}
with(oTBody){
style.pixelHeight = height - oTitle.offsetHeight;
}
}
}
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;//单元格是否被选中
oSortBtn = null;//排序按钮
curScrollLeftStatus = 0;//水平滚动条当前的scrollLeft
curScrollTopStatus = 0;//垂直滚动条当前的scrollTop
//oEditor = null;//当前输入框
oCurCell = null;//当前Cell
curContent = null;//当前cell中的内容
curPage = 1;//当前页
oPageSize = 20;//每页显示的记录数,默认为20条
ifFirst = true;
///////////////////////////////////////////////////////////
while(element.all.length > 0){
if(element.all(element.all.length-1)){
objLeafElement = element.all(element.all.length - 1);
while(objLeafElement.childNodes.length > 0){
objLeafElement = objLeafElement.childNodes(0);
}//End of while
if(objLeafElement.parentElement)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -