📄 olapgrid.js
字号:
/* * Bindows 1.5 * http://www.bindows.net/ * Copyright (c) 2003-2005 MB Technologies * * Bindows(tm) belongs to MB Technologies (Georgia, USA). All rights reserved. * You are not allowed to copy or modify this code. Commercial use requires * license. */function BiOlapGridCellInfo()
{if(_biInPrototype)return;BiObject.call(this);}
_p=_biExtend(BiOlapGridCellInfo,BiObject,"BiOlapGridCellInfo");_p._header=false;_p._body=false;BiOlapGridCellInfo.prototype.getHeader=function(){return this._header;};BiOlapGridCellInfo.prototype.setHeader=function(v){this._header=v;};BiOlapGridCellInfo.prototype.getBody=function(){return this._body;};BiOlapGridCellInfo.prototype.setBody=function(v){this._body=v;};BiOlapGridCellInfo.prototype.getRow=function(){return this._row;};BiOlapGridCellInfo.prototype.setRow=function(v){this._row=v;};BiOlapGridCellInfo.prototype.getColumn=function(){return this._column;};BiOlapGridCellInfo.prototype.setColumn=function(v){this._column=v;};BiOlapGridCellInfo.prototype.getDimension=function(){return this._dimension;};BiOlapGridCellInfo.prototype.setDimension=function(v){this._dimension=v;};BiOlapGridCellInfo.prototype.getAxis=function(){return this._axis;};BiOlapGridCellInfo.prototype.setAxis=function(v){this._axis=v;};BiOlapGridCellInfo.prototype.getAxisPosition=function(){return this._axisPosition;};BiOlapGridCellInfo.prototype.setAxisPosition=function(v){this._axisPosition=v;};BiOlapGridCellInfo.prototype.getQuadrant=function(){return this._quadrant;};BiOlapGridCellInfo.prototype.setQuadrant=function(v){this._quadrant=v;};_p.equals=function(oInfo)
{return this._axis==oInfo._axis&&(this._header&&oInfo._header&&this._dimension==oInfo._dimension&&this._axisPosition==oInfo._axisPosition||this._body&&oInfo._body&&this._row==oInfo._row&&this._column==oInfo._column);};function BiOlapGridDropMarker()
{if(_biInPrototype)return;BiComponent.call(this);this.setBackColor("highlight");}
_p=_biExtend(BiOlapGridDropMarker,BiComponent,"BiOlapGridDropMarker");_p.showDimensionDropMarker=function(grid,info,before)
{var vm=grid.getViewManager();if(this.getParent()!=grid)
grid.add(this,null,true);var left,right;if(info.getAxis()==0)
{if(before)
this.setTop(vm.getDimensionTop(info.getDimension())-1);else this.setTop(vm.getDimensionTop(info.getDimension())+vm.getDimensionHeight(info.getDimension())-1);this.setHeight(2);this.setBottom(null);left=vm.getShowHeaders(1)?vm.getAxisWidth():0;right=0;}
else {if(before)
left=vm.getDimensionLeft(info.getDimension())-1;else left=vm.getDimensionLeft(info.getDimension())+vm.getDimensionWidth(info.getDimension())-1;this.setWidth(2);right=null;this.setTop(vm.getShowHeaders(0)?vm.getAxisHeight():0);this.setBottom(0);}
if(grid.getRightToLeft())
{this.setRight(left)
this.setLeft(right);}
else {this.setLeft(left)
this.setRight(right);}};_p.hide=function()
{if(this._parent)
this._parent.remove(this);};function BiOlapGridDragEvent(sType,oDragEvent)
{if(_biInPrototype)return;BiDragEvent.call(this,sType,oDragEvent&&oDragEvent._event);};_p=_biExtend(BiOlapGridDragEvent,BiDragEvent,"BiOlapGridDragEvent");BiOlapGridDragEvent.BEFORE=1;BiOlapGridDragEvent.AFTER=2;BiOlapGridDragEvent.OVER=3;_p.initEvent=function(oSrc,oDst,nRelative)
{this._sourceInfo=oSrc;this._destinationInfo=oDst;this._relative=nRelative||BiOlapGridDragEvent.OVER;};BiOlapGridDragEvent.prototype.getDestinationInfo=function(){return this._destinationInfo;};BiOlapGridDragEvent.prototype.getSourceInfo=function(){return this._sourceInfo;};BiOlapGridDragEvent.prototype.getRelative=function(){return this._relative;};function BiOlapGrid()
{if(_biInPrototype)return;BiTreeViewBase.call(this);this.setCssClassName("bi-olap-grid");this.setAppearance("olap-grid");this._selectionModel=new BiOlapGridSelectionModel(this);this._stateManager=new BiOlapGridStateManager;this._viewManager=new BiOlapGridViewManager(this);this._invalidSelectionAreas=new BiAreaCollection;if(!this._useNativeScrollBars)
{this._vScrollBar.setUnitIncrement(18);}
this._stateManager.addEventListener("hoverchanged",this._onHoverChanged,this);}
_p=_biExtend(BiOlapGrid,BiTreeViewBase,"BiOlapGrid");_p._allowHeaderSelection=true;BiOlapGrid.prototype.setAllowHeaderSelection=function(v){this._allowHeaderSelection=v;};_p.getAllowHeaderSelection=function()
{return this._allowHeaderSelection&&!this.getCanReorganizeDimensions();};_p.setViewManager=function(o)
{if(o)
o._olapGrid=this;this._viewManager=o;};_p.setDataModel=function(dm)
{if(this._dataModel!=dm)
{if(this._dataModel)
{this._dataModel.removeEventListener("datachanged",this._onDataChanged,this);this._dataModel.removeEventListener("beforedatastructurechanged",this._onBeforeDataStructureChanged,this);this._dataModel.removeEventListener("datastructurechanged",this._onDataStructureChanged,this);}
this._dataModel=dm;if(dm!=null)
{dm.addEventListener("datachanged",this._onDataChanged,this);dm.addEventListener("beforedatastructurechanged",this._onBeforeDataStructureChanged,this);dm.addEventListener("datastructurechanged",this._onDataStructureChanged,this);}
this._viewManager.resetCache();this._forceMeasure=true;this.updateContentSize();this.updateSize();this._updateGrid(true,true,true);}};_p._onBiTreeViewBaseScroll=function()
{if(!this._preventScrollUpdates)
{this._resetUpdateCache();this._viewManager.setScrollLeft(this._getInternalScrollLeft());this._viewManager.setScrollTop(this._getInternalScrollTop());if(BiBrowserCheck.moz)
{if(this._element)
this._element.scrollTop=0;if(this._gridBodyContentElement)
this._gridBodyContentElement.scrollTop=0;if(this._gridFixedTopElement&&this._gridFixedTopElement.lastChild&&/bi-olap-grid-body-content/.test(this._gridFixedTopElement.lastChild.className))
this._gridFixedTopElement.lastChild.scrollTop=0;if(this._gridFixedCornerElement&&this._gridFixedCornerElement.lastChild&&/bi-olap-grid-body-content/.test(this._gridFixedCornerElement.lastChild.className))
this._gridFixedCornerElement.lastChild.scrollTop=0;}
this._updateGrid();this.dispatchEvent(new BiEvent("scroll"));}};_p.updateContentSize=function()
{var dm=this.getDataModel();var vm=this.getViewManager();if(!this.getCreated())
return;if(this._useNativeScrollBars)
{var cw=this._gridBodyElement.clientWidth;var ch=this._gridBodyElement.clientHeight;this._gridBodyFillerElement.style.width=vm.getVisibleCellsWidth()+"px";this._gridBodyFillerElement.style.height=vm.getVisibleCellsHeight()+"px";vm.setScrollLeft(this._getInternalScrollLeft());vm.setScrollTop(this._getInternalScrollTop());this._measure();var newCw=this._gridBodyElement.clientWidth;var newCh=this._gridBodyElement.clientHeight;if(cw!=newCw||ch!=newCh)
{this._clientSizeChanged=true;}}
else {this._syncScrollBars();this._doCustomOverflow();}
this._contentSizeDirty=false;};_p.updateSize=function()
{if(!this.getCreated())
return;this._measure();var vm=this.getViewManager();var rtl=this.getRightToLeft();var axis=0;var fixedLeftWidth=vm.getFixedLeftWidth();var fixedTopHeight=vm.getFixedTopHeight();var availWidth=this._gridBodyElement.clientWidth;var availHeight=this._gridBodyElement.clientHeight;var clientWidth=this._element.clientWidth;var scrollBarWidth=clientWidth-availWidth;if(this._useNativeScrollBars)
{this._gridBodyFillerElement.style.marginTop=fixedTopHeight+"px";this._gridBodyFillerElement.style.marginLeft=rtl?0:fixedLeftWidth+"px";this._gridBodyFillerElement.style.marginRight=rtl?fixedLeftWidth+"px":0;}
else {this._syncScrollBars();}
this._gridBodyContentElement.style.height=Math.max(0,availHeight-fixedTopHeight)+"px";this._gridBodyContentElement.style.top=fixedTopHeight+"px";this._gridBodyContentElement.style.width=Math.max(0,availWidth-fixedLeftWidth)+"px";this._gridBodyContentElement.style.left=rtl?scrollBarWidth:fixedLeftWidth+"px";if(fixedLeftWidth>0)
{this._gridFixedLeftElement.style.display="block";this._gridFixedCornerElement.style.display="block";this._gridFixedLeftElement.style.width=Math.min(availWidth,fixedLeftWidth)+"px";this._gridFixedCornerElement.style.width=Math.min(availWidth,fixedLeftWidth)+"px";this._gridFixedLeftElement.style.height=Math.max(0,availHeight-fixedTopHeight)+"px";this._gridFixedLeftElement.style.top=fixedTopHeight+"px";this._gridFixedLeftElement.style.left=this._gridFixedCornerElement.style.left=rtl?clientWidth-fixedLeftWidth+"px":0;}
else {this._gridFixedLeftElement.style.display="none";this._gridFixedCornerElement.style.display="none";}
if(fixedTopHeight>0)
{this._gridFixedTopElement.style.display="block";this._gridFixedTopElement.style.height=Math.min(availHeight,fixedTopHeight)+"px";this._gridFixedTopElement.style.width=Math.max(0,availWidth-fixedLeftWidth)+"px";this._gridFixedTopElement.style.left=rtl?scrollBarWidth:fixedLeftWidth+"px";if(fixedLeftWidth>0)
{this._gridFixedCornerElement.style.display="block";this._gridFixedCornerElement.style.height=Math.min(availHeight,fixedTopHeight)+"px";}}
else {this._gridFixedTopElement.style.display="none";this._gridFixedCornerElement.style.display="none";}
vm.setScrollLeft(this._getInternalScrollLeft());vm.setScrollTop(this._getInternalScrollTop());};_p._doCustomOverflow=function()
{if(!this.getCreated())
{return;}
var vm=this.getViewManager();var dm=this.getDataModel();var contentWidth=vm.getVisibleCellsWidth(0);var clientWidth=this._element.clientWidth;var availWidth=clientWidth;var contentHeight=dm?vm.getVisibleCellsHeight(1):0;var clientHeight=this._element.clientHeight;var availHeight=clientHeight;var vpw=this._vScrollBar.getPreferredWidth();var hph=this._hScrollBar.getPreferredHeight();var rtl=this.getRightToLeft();contentWidth+=vm.getFixedLeftWidth();contentHeight+=vm.getFixedTopHeight();var ox=this.getOverflowX();var oy=this.getOverflowY();var hVis,vVis;var oldVisV=this._vScrollBar.getVisible();var oldVisH=this._hScrollBar.getVisible();if(ox=="hidden")
{hVis=false;}
else if(ox=="scroll")
{hVis=true;}
else {if(oldVisV)
{hVis=contentWidth>availWidth-vpw;}
else {hVis=contentWidth>availWidth;}}
if(hVis)
{availHeight-=hph;}
if(oy=="hidden")
{vVis=false;}
else if(oy=="scroll")
{vVis=true;}
else {vVis=contentHeight>availHeight;}
if(vVis)
{availWidth-=vpw;}
this._gridBodyElement.style.width=Math.max(0,availWidth)+"px";this._gridBodyElement.style.height=Math.max(0,availHeight)+"px";this._beginScrollBatch();this._syncScrollBars();this._vScrollBar.setExtent(availHeight);this._hScrollBar.setExtent(availWidth);this._vScrollBar.setVisible(vVis);this._hScrollBar.setVisible(hVis);this._vScrollBar.setTop(0);this._vScrollBar.setLeft(rtl?0:clientWidth-vpw);this._vScrollBar.setHeight(clientHeight-(hVis?hph:0));this._hScrollBar.setLeft(vVis&&rtl?vpw:0);this._hScrollBar.setTop(clientHeight-hph);this._hScrollBar.setWidth(clientWidth-(vVis?vpw:0));if(vVis!=oldVisV||hVis!=oldVisH)
{this._doCustomOverflow();this.updateSize();}
this._endScrollBatch();};_p.getHtmlCode=function(nStartCol,nStartRow,nWidth,nHeight)
{this._createUpdateCache();var uc=this._updateCache;var dm=this.getDataModel();var vm=this.getViewManager();var sm=this._selectionModel;if(!dm)
return"";var axis=0;var startRow=nStartRow;var startCol=nStartCol;var rowCount=dm.getAxisPositionWidth(1-axis);var colCount=dm.getAxisPositionWidth(axis);var ieExtraPadding=uc.ieExtraPadding;var ieNoBr=uc.ieNoBr;var ieNoBrClose=uc.ieNoBrClose;var sum=0;var sb=[];var yPos=0;var xPos,w,wl,my;mx=startCol;if(mx!=null)
{my=startRow;while(my!=null&&my<rowCount&&yPos<nHeight)
{rowHeight=vm.getCellHeight(my);sb.push("<tr class=\"","\" style=\"height:",rowHeight,"px\">");mx=startCol;xPos=0;while(mx!=null&&mx<colCount&&xPos<nWidth)
{w=vm.getCellWidth(mx);sb.push("<td style=\"width:",(w-vm.getCellPaddingX()),"px;height:",rowHeight,"px;",dm.getCellStyle(mx,my),"\" class=\"",(sm.getCellSelected(mx,my)?"selected":""),(sm.getCellIsAnchor(mx,my)?" anchor":""),"\">",ieNoBr,(dm.getHasIcon(mx,my)?"<img alt=\"\" src=\""+dm.getIcon(mx,my)+"\" style=\""+dm.getIconStyle(mx,my)+"\" class=\"icon\">":""),dm.getCellText(mx,my),ieNoBrClose,"</td>");if(this._getHasAttachedComponent(mx,my))
{var ac=this._getAttachedComponent(mx,my);this._attachedComponents[ac.toHashCode()]={col:mx,row:my,width:w,height:rowHeight,component:ac};}
xPos+=w;mx=vm.getNextVisibleCell(axis,mx);}
if(xPos<nWidth)
sb.push("<td class=\"horizontal-filler\" style=\"width:",(nWidth-xPos),"px;",dm.getFillerCellStyle(mx,my),"\"> </td>");sb.push("</tr>");yPos+=rowHeight;my=vm.getNextVisibleCell(1-axis,my);}
if(yPos<nHeight)
{mx=startCol;xPos=0;sb.push("<tr style=\"height:",(nHeight-yPos),"px;\" class=\"vertical-filler\">");while(mx!=null&&xPos<nWidth)
{w=vm.getCellWidth(mx);sb.push("<td style=\"width:",(w-vm.getCellPaddingX()),"px;",dm.getFillerCellStyle(mx,my),"\"","> </td>");xPos+=w;mx=vm.getNextVisibleCell(mx);}
if(xPos<nWidth)
sb.push("<td class=\"horizontal-filler\" style=\"width:",(nWidth-xPos),"px;",dm.getFillerCellStyle(mx,my),"\"> </td>");sb.push("</tr>");}}
sb.push("</tbody></table>");return"<table cellspacing=\"0\" class=\"bi-olap-grid-table\" style=\"width:"+xPos+"px\"><tbody class=\""+(vm.getShowGridLines()?"bi-show-grid-lines":"")+(this.getContainsFocus()?" focused":"")+"\">"+sb.join("");};_p.getFixedTopHtmlCode=function(nScrollLeft,nWidth,nHeight)
{this._createUpdateCache();var uc=this._updateCache;var vm=this.getViewManager();var axis=0;var headerHeight=vm.getAxisHeight();var fixedTopHeight=vm.getFixedTopHeight();var contentHeight=fixedTopHeight-headerHeight;if(fixedTopHeight<=0||nWidth<=0)
{return"";}
else if(headerHeight>=nHeight||nWidth<=0)
{return this.getHeadersHtmlCode(uc.startCol,nWidth,headerHeight);}
else {var startRow=vm.getFixedCell(1-axis);if(!vm.getCellVisible(1-axis,startRow))
startRow=vm.getNextVisibleCell(1-axis,startRow);if(startRow==null||startRow>=vm.getNonFixedCell(1-axis))
return this.getHeadersHtmlCode(uc.startCol,nWidth,headerHeight);else return this.getHeadersHtmlCode(uc.startCol,nWidth,headerHeight)+"<div class=\"bi-olap-grid-body-content bi-olap-grid-fixed-bottom-border\" "+"style=\"left:0;top:"+headerHeight+"px;"+"width:"+nWidth+"px;"+"height:"+contentHeight+"px;\">"+this.getHtmlCode(uc.startCol,startRow,nWidth,contentHeight)+"</div>";}};_p.getHeadersHtmlCode=function(nStartCol,nWidth,nHeight)
{this._createUpdateCache();var uc=this._updateCache;var dm=this.getDataModel();var vm=this.getViewManager();var sm=this._stateManager;var startCol=nStartCol;var axis=0;var dimCount=dm.getAxisDimensionCount(axis);var colCount=dm.getAxisPositionWidth(axis);var sb=[];var mx,xPos,my,yPos,h,w,dist,deltaLeft;var startFiller=0;var fillerLeftPos=0;var fillerLeft=0;var minStart=Infinity;var maxWidth=nWidth;var leftProp=this.getRightToLeft()?"right":"left";my=vm.getFirstVisibleDimension(axis);if(dm!=null&&my!=null&&startCol!=null)
{for(yPos=0;my!=null&&my<dimCount&&yPos<nHeight;my=vm.getNextDimension(axis,my),yPos+=h)
{h=vm.getDimensionHeight(my);xPos=0;mx=startCol;fillerLeft=0;var startPos=vm.getAxisCellStartPosition(axis,my,mx);minStart=vm.getMinCellPosition(axis,startPos,minStart);dist=vm.getAxisPositionDistance(axis,minStart,startPos);if(dist>0)
{fillerLeftPos=dist;fillerLeft=vm.getCellLeft(startPos)-vm.getCellLeft(minStart);xPos+=fillerLeft;}
mx=startPos;deltaLeft=vm.getCellLeft(startCol)-vm.getCellLeft(minStart);while(mx!=null&&xPos<nWidth+deltaLeft)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -