📄 grids.js
字号:
this._resizeDir="";else if(e.getOffsetX()<=8&&ps)
this._resizeDir="w";else if(e.getOffsetX()+8>=this.getWidth())
this._resizeDir="e";else this._resizeDir="";if(this._resizeDir!=""){if((new BiBrowserCheck).getIe55())
this.setCursor("hand");else if((new BiBrowserCheck).getIe())
this.setCursor("col-resize");else this.setCursor("e-resize");}
else this.setCursor("");};function BiGridHeaderFiller(){BiGridHeader.call(this);};_p=_biExtend(BiGridHeaderFiller,BiGridHeader,"BiGridHeaderFiller");_p._sortable=false;_p._resizable=false;_p._movable=false;function BiGridHeaderCorner()
{if(_biInPrototype)return;BiGridHeader.call(this);this.setLocation(0,0);this.setRight(null);this.setBottom(null);}
_p=_biExtend(BiGridHeaderCorner,BiGridHeader,"BiGridHeaderCorner");_p._sortable=false;_p._resizable=false;_p._movable=false;function BiGridRowHeaders()
{if(_biInPrototype)return;BiComponent.call(this);this.setCssClassName("bi-grid-row-headers");}
_p=_biExtend(BiGridRowHeaders,BiComponent,"BiGridRowHeaders");_p._rowHeight=18;_p._setHeadersHtml=function(s)
{if(this.getCreated())
{this._element.innerHTML=s+"<div class=\"bi-grid-row-header-filler grid-header\"></div>";}};function BiAbstractGrid(){if(_biInPrototype)return;BiComponent.call(this);this.setTabIndex(1);this.setHideFocus(true);this._rows=[];this._nodes=this._rows;this._gridElements={};this._columns=[];this._columnOrders=[];this._invertedColumnOrders=[];this._columnWidths=[];this._columnNames=[];this._columnAligns=[];this._columnSortTypes=[];this.setSize(300,300);application.getThemeManager().addEventListener("themechanged",this.update,this);}
_p=_biExtend(BiAbstractGrid,BiComponent,"BiAbstractGrid");_p._gridHeadersConstructor=BiGridHeaders;_p._gridColumnConstructor=BiGridColumn;_p._lastKeyPress=0;_p._accumulatedKeys="";_p._columnCount=0;_p._columns=null;_p._columnOrders=null;_p._invertedColumnOrders=null;_p._columnWidths=null;_p._columnNames=null;_p._columnAligns=null;_p._columnSortTypes=null;_p._iconColumn= -1;_p._showHeaders=true;_p._showRowHeaders=false;_p._liveResize=false;_p._sortColumn= -1;_p._ascending=null;_p._selectionModel=null;_p._allNodes=null;_p._gridCreated=false;_p._rowHeight=18;_p._fontSize=11;_p._rowHeadersWidth=30;_p._headersHeight=18;_p._overflowX="auto";_p._overflowY="auto";_p._allowInlineFind=true;BiAbstractGrid.prototype.getAllowInlineFind=function(){return this._allowInlineFind;};BiAbstractGrid.prototype.setAllowInlineFind=function(v){this._allowInlineFind=v;};BiAbstractGrid.prototype.getColumns=function(){return this._columns;};BiAbstractGrid.prototype.getShowRowHeaders=function(){return this._showRowHeaders;};BiAbstractGrid.prototype.setShowRowHeaders=function(v){this._showRowHeaders=v;};BiAbstractGrid.prototype.getRowHeadersWidth=function(){return this._rowHeadersWidth;};BiAbstractGrid.prototype.setRowHeadersWidth=function(v){this._rowHeadersWidth=v;};BiAbstractGrid.prototype.getSortColumn=function(){return this._sortColumn;};BiAbstractGrid.prototype.getAscending=function(){return this._ascending;};BiAbstractGrid.prototype.getRowHeight=function(){return this._rowHeight;};BiAbstractGrid.prototype.setRowHeight=function(v){this._rowHeight=v;};BiAbstractGrid.prototype.getHeaders=function(){return this._headers;};_p._getFillerHeight=function(){return this._showHeaders?this._headersHeight:0;};_p._getFillerWidth=function(){return this._showRowHeaders?this._rowHeadersWidth:0;};_p.layoutAllChildren=function(){this._layoutHeaders();BiComponent.prototype.layoutAllChildren.call(this);};BiAbstractGrid.prototype.getColumnCount=function(){return this._columnCount;};_p.setColumnCount=function(n)
{if(this._columnCount>n)
{for(var i=n;i<this._columnCount;i++)
{this._headers.remove(this._columns[i].getHeader());this._columns[i].dispose();}
this._columns=this._columns.slice(0,n);}
else {var c;for(var i=this._columnCount;i<n;i++)
{c=this._columns[i]=new this._gridColumnConstructor(this._columnNames[i]);c._columnIndex=i;c._orderIndex=i;c._grid=this;c.setAlign(this._columnAligns[i]);this._headers.add(c.getHeader());}
this.setColumnOrders(BiAbstractGrid._expandArray2(this._columnOrders,n,Number));this.setColumnWidths(BiAbstractGrid._expandArray(this._columnWidths,n,100,Number));this.setColumnNames(BiAbstractGrid._expandArray(this._columnNames,n,"Untitled",String));this.setColumnAligns(BiAbstractGrid._expandArray(this._columnAligns,n,"left",String));this.setColumnSortTypes(BiAbstractGrid._expandArray(this._columnSortTypes,n,"string",String));}
this._columnCount=n;this._headers.setColumnCount(n);};BiAbstractGrid._expandArray=function(a,n,v,f){for(var i=a.length;i<n;i++)
a[i]=f(v);return a;};BiAbstractGrid._expandArray2=function(a,n,f){for(var i=a.length;i<n;i++)
a[i]=f(i);return a;};BiAbstractGrid.prototype.getColumnWidths=function(){return this._columnWidths;};_p.setColumnWidths=function(aWidths){this._columnWidths=aWidths;for(var i=0;i<this._columnCount;i++){this._columns[i].setWidth(aWidths[i]);}
this._headers.setColumnWidths(aWidths);};_p.getColumnWidth=function(x){return this._columns[x].getWidth();};BiAbstractGrid.prototype.getColumnOrders=function(){return this._columnOrders;};_p.setColumnOrders=function(aOrderIndexes){this._columnOrders=aOrderIndexes;for(var i=0;i<this._columnCount;i++){this._columns[aOrderIndexes[i]]._orderIndex=i;}
this._invertedColumnOrders=new Array(aOrderIndexes.length);for(var i=0;i<aOrderIndexes.length;i++){this._invertedColumnOrders[aOrderIndexes[i]]=i;}
this._headers.setColumnOrders(aOrderIndexes);};_p.getColumnOrder=function(x){return this._columns[x].getOrderIndex();};BiAbstractGrid.prototype.getColumnAligns=function(){return this._columnAligns;};_p.setColumnAligns=function(aAligns){this._columnAligns=aAligns;for(var i=0;i<this._columnCount;i++){this._columns[i].setAlign(aAligns[i]);}};_p.getColumnAlign=function(x){return this._columns[x].getAlign();};BiAbstractGrid.prototype.getColumnNames=function(){return this._columnNames;};_p.setColumnNames=function(aNames){this._columnNames=aNames;for(var i=0;i<this._columnCount;i++){this._columns[i].setName(aNames[i]);}};_p.getColumnName=function(x){return this._columns[x].getName();};BiAbstractGrid.prototype.getColumnSortTypes=function(){return this._columnSortTypes;};_p.setColumnSortTypes=function(aSortTypes){this._columnSortTypes=aSortTypes;for(var i=0;i<this._columnCount;i++){this._columns[i].setSortType(aSortTypes[i]);}};_p.getColumnSortType=function(x){return this._columns[x].getSortType();};BiAbstractGrid.prototype.getIconColumn=function(){return this._iconColumn;};_p.setIconColumn=function(n){if(this._columns[this._iconColumn])
this._columns[this._iconColumn]._iconColumn=false;this._iconColumn=n;if(this._columns[this._iconColumn])
this._columns[this._iconColumn]._iconColumn=true;};_p.setFitColumnWidths=function(b)
{this._headers.setFitColumnWidths(b);this.setOverflowX(b?"hidden":"auto");};_p.getFitColumnWidths=function()
{return this._headers.getFitColumnWidths();};BiAbstractGrid.prototype.getLiveResize=function(){return this._liveResize;};_p.setLiveResize=function(b){if(this._liveResize!=b){if(b)
this._headers.addEventListener("columnwidthschanging",this.updateColumns,this);else this._headers.removeEventListener("columnwidthschanging",this.updateColumns,this);this._liveResize=b;}};BiAbstractGrid.prototype.getShowHeaders=function(){return this._showHeaders;};BiAbstractGrid.prototype.setShowHeaders=function(v){this._showHeaders=v;};_p.setShowHeaders=function(b){if(this._showHeaders!=b){this._showHeaders=b;this._headers.setVisible(b);if(this._headerCorner)
this._headerCorner.setVisible(this.getShowHeaders()&&this.getShowRowHeaders());if(this.getCreated())
this._gridBodyElement.style.paddingTop=this._getFillerHeight()+"px";if(this._rowHeaders)
{this._rowHeaders.setTop(this._getFillerHeight());this._updateRowHeadersHeight();}
if(b)
this.updateHeadersWidth();}};BiAbstractGrid.prototype.getHeadersHeight=function(){return this._headersHeight;};BiAbstractGrid.prototype.setHeadersHeight=function(v){this._headersHeight=v;};_p.setHeadersHeight=function(n)
{if(this._headersHeight!=n)
{this._headersHeight=n;this._headers.setHeight(n);if(this._headerCorner)
this._headerCorner.setHeight(n);if(this.getCreated())
this._gridBodyElement.style.paddingTop=this._getFillerHeight()+"px";if(this._rowHeaders)
{this._rowHeaders.setTop(this._getFillerHeight());this._updateRowHeadersHeight();}}};_p.update=function(){this.updateColumns();this.updateData();};_p.updateColumns=function(){var i;if(this.getCreated()){this._removeStyleRules();var rs=this._getStyleRules();var l=rs.length;if(BiBrowserCheck.ie)
{for(i=0;i<l;i++)
this._styleSheet.addRule(rs[i].selector,rs[i].style);}
else {for(i=0;i<l;i++)
this._styleSheet.insertRule(rs[i].selector+"{"+rs[i].style+"}",this._styleSheet.cssRules.length);}
this.updateHeadersWidth();}};_p._removeStyleRules=function(){if(this._styleSheet)
{var rules;if(BiBrowserCheck.ie)
rules=this._styleSheet.rules;else rules=this._styleSheet.cssRules;var l=rules.length;var s="#"+this.getHtmlProperty("id");if(BiBrowserCheck.ie)
{for(var i=rules.length-1;i>=0;i--){if(rules[i].selectorText.indexOf(s)==0){this._styleSheet.removeRule(i);}}}
else {for(var i=rules.length-1;i>=0;i--){if(rules[i].selectorText.indexOf(s)==0){this._styleSheet.deleteRule(i);}}}}};_p.updateData=function(){if(this.getCreated()){this._clearCache();this._gridBodyElement.innerHTML=this.getGridBodyHtml();this.updateHeadersWidth();this._gridCreated=true;}};_p.updateHeadersWidth=function()
{if(this.getCreated()&&this._headers.getCreated())
{var oldWidth=this._headers.getWidth();var fw=this._getFillerWidth();var newWidth=this._gridBodyElement.clientWidth-fw;this._headers.setWidth(newWidth);this._headers.setLeft(this.getRightToLeft()?this._gridBodyElement.offsetWidth-this._gridBodyElement.clientWidth:fw);if(this._headerCorner)
{if(this.getRightToLeft())
this._headerCorner.setLeft(this._gridBodyElement.offsetWidth-fw);else this._headerCorner.setLeft(0);}
if(oldWidth==newWidth)
this._headers.layoutAllChildren();}};_p._updateHeadersWidth=function(){var t=new BiTimer(1);t.addEventListener("tick",function(e){t.stop();this.updateHeadersWidth();t.dispose();},this);t.start();};_p._create=function(oDoc){BiComponent.prototype._create.call(this,oDoc);this._styleSheet=BiAbstractGrid._styleSheet;if(!this._styleSheet){if(BiBrowserCheck.ie)
this._styleSheet=this._document.createStyleSheet();else {var el=this._document.createElement("STYLE");el.type="text/css";this._document.getElementsByTagName("HEAD")[0].appendChild(el);this._styleSheet=el.sheet;}
BiAbstractGrid._styleSheet=this._styleSheet;}
this._gridBodyElement=this._document.createElement("DIV");this._gridBodyElement.className="bi-grid-body";this._gridBodyElement._biComponent=this;this._gridBodyElement.onscroll=BiComponent.__oninlineevent;this._element.appendChild(this._gridBodyElement);if(this.getRightToLeft())
this._gridBodyElement.style.paddingRight=this._getFillerWidth()+"px";else this._gridBodyElement.style.paddingLeft=this._getFillerWidth()+"px";this._gridBodyElement.style.paddingTop=this._getFillerHeight()+"px";this._gridBodyElement.style.overflowX=this._overflowX;this._gridBodyElement.style.overflowY=this._overflowY;};_p.dispose=function(){if(this._disposed)return;this._removeStyleRules();BiComponent.prototype.dispose.call(this);this._selectionModel.dispose();this._selectionModel=null;application.getThemeManager().removeEventListener("themechanged",this.update,this);for(var i=this._rows.length-1;i>=0;i--)
this._rows[i].dispose();this._clearCache();this._styleSheet=null
if(this._gridBodyElement)
{this._gridBodyElement._biComponent=null;this._gridBodyElement.onscroll=null;}
this._gridBodyElement=null;if(this._dataSource)
{this._dataSource.dispose();this._dataSource=null;}};_p._getAllNodes=function(){if(this._allNodes==null){this._allNodes={};var cs=this._rows;var l=cs.length;for(var i=0;i<l;i++)
cs[i]._getAllNodes(this._allNodes);}
return this._allNodes;};_p._getGridElement=function(oNode){if(!this._created)return null;var hc=oNode.toHashCode();if(!this._gridElements[hc])
{this._gridElements[hc]=this._document.getElementById(hc);}
return this._gridElements[hc];};_p._clearCache=function(){this._depth=null;this._allNodes=null;for(var hc in this._gridElements)
delete this._gridElements[hc];};_p.getGridBodyHtml=function(){var cs=this._rows;var l=cs.length;var sb=new Array(l);for(var i=0;i<l;i++)
sb[i]=cs[i].getHtml();return sb.join("");};_p.getSelectedNode=function(){return this.getSelectedRows()[0];};_p.getSelectedRow=function(){return this.getSelectedRows()[0];};_p.getSelectedNodes=function(){return this._selectionModel.getSelectedItems();};_p.getSelectedRows=function(){return this._selectionModel.getSelectedItems();};_p.setMultipleSelection=function(b){this._selectionModel.setMultipleSelection(b);};_p.getMultipleSelection=function(){return this._selectionModel.getMultipleSelection();};BiAbstractGrid.prototype.getSelectionModel=function(){return this._selectionModel;};_p.setSelectionModel=function(sm){if(this._selectionModel!=sm){if(this._selectionModel!=null)
this._selectionModel.deselectAll();this._selectionModel=sm;}};_p.findString=function(sText,nStartIndex){return this._findItem(sText,nStartIndex||0,"String");};_p.findStringExact=function(sText,nStartIndex){return this._findItem(sText,nStartIndex||0,"StringExact");};_p.setScrollLeft=function(n)
{if(this.getCreated())
{this._gridBodyElement.scrollLeft=n;if(BiBrowserCheck.moz)
this._headers.setScrollLeft(this.getScrollLeft());}};_p.getScrollLeft=function()
{if(this.getCreated())
return this._gridBodyElement.scrollLeft;};_p.setScrollTop=function(n){if(this.getCreated())
this._gridBodyElement.scrollTop=n;};_p.getScrollTop=function(n){if(this.getCreated())
return this._gridBodyElement.scrollTop;};_p.getScrollWidth=function(n){if(this.getCreated())
return this._gridBodyElement.scrollWidth;};_p.getScrollHeight=function(n){if(this.getCreated())
return this._gridBodyElement.scrollHeight;};_p.getClientWidth=function(){if(!this._created)
throw new Error("Visual property on non created component");return this._gridBodyElement.clientWidth;};_p.getClientHeight=function(){if(!this._created)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -