📄 grids.js
字号:
if (this._disposed) return; this._grid = null; this._icon = null;};function BiGridColumn(sName){ BiObject.call(this); if (sName) this._name = sName; this._header = new this._gridHeaderConstructor(this._name);};var _p = BiGridColumn.prototype = new BiObject;_p._className = "BiGridColumn";_p._gridHeaderConstructor = BiGridHeader;_p._name = "Untitled";_p._width = 200;_p._align = "left";_p._indentColumn = false;_p._iconColumn = false;_p._orderIndex = -1;_p._columnIndex = -1;_p._grid = null;_p._sortType = "string";BiGridColumn.prototype.getHeader = function(){ return this._header;} ;BiGridColumn.prototype.getGrid = function(){ return this._grid;} ;BiGridColumn.prototype.getIndentColumn = function(){ return this._indentColumn;} ;BiGridColumn.prototype.getIconColumn = function(){ return this._iconColumn;} ;BiGridColumn.prototype.getOrderIndex = function(){ return this._orderIndex;} ;BiGridColumn.prototype.getName = function(){ return this._name;} ;BiGridColumn.prototype.getWidth = function(){ return this._width;} ;BiGridColumn.prototype.getColumnIndex = function(){ return this._columnIndex;} ;_p.getTree = _p.getGrid;_p.setAlign = function(s){ this._align = s; this._grid._columnAligns[this._columnIndex] = s; this._header.setAlign(s);};_p.getAlign = function(){ return this._align || "left";} ;_p.setName = function(s){ this._name = s; this._grid._columnNames[this._columnIndex] = s; this._header.setText(s);};_p.setWidth = function(n){ this._width = n; this._grid._columnWidths[this._columnIndex] = n;};_p.setIndentColumn = function(b){ if (this._indentColumn != b) ; { this._indentColumn = b; if (b) this._grid.setIndentColumn(this._columnIndex); }};_p.setIconColumn = function(b){ if (this._iconColumn != b) ; { this._iconColumn = b; if (b) this._grid.setIconColumn(this._columnIndex); }};_p.dispose = function(){ if (this._disposed) return; BiObject.prototype.dispose.call(this); this._header.dispose(); this._header = null; this._grid = null;};BiGridColumn.prototype.getSortType = function(){ return this._sortType;} ;_p.setSortType = function(sType){ this._sortType = sType;} ;_p.getSortFunction = function(){ var f; switch (this._sortType.toLowerCase()) { case "string": f = BiGridColumn.stringCompare; break; case "caseinsensitivestring": f = BiGridColumn.caseInsensitiveStringCompare; break; case "number": f = BiGridColumn.numberCompare; break; case "date": f = BiGridColumn.dateCompare; break; default: f = BiGridColumn.lessThanCompare; } var index = this._columnIndex; return function(r1, r2) { return f(r1.getData(index), r2.getData(index)); } ;};BiGridColumn.numberCompare = function(n1, n2){ return n1 - n2;} ;BiGridColumn.dateCompare = BiGridColumn.numberCompare;BiGridColumn.lessThanCompare = function(v1, v2){ if (v1 < v2) return -1; if (v2 < v1) return 1; return 0;};BiGridColumn.stringCompare = BiGridColumn.lessThanCompare;BiGridColumn.caseInsensitiveStringCompare = function(s1, s2){ return BiGridColumn.stringCompare(s1.toLowerCase(), s2.toLowerCase());} ;function BiTree(){ BiAbstractGrid.call(this); this.setCssClassName("bi-tree"); this._selectionModel = new BiTreeSelectionModel(this); this._selectionModel.setMultipleSelection(false); this._headers = new this._gridHeadersConstructor; this.addEventListener("mousedown", this._onMouseEvent); this.addEventListener("mouseup", this._onMouseEvent); this.addEventListener("click", this._onMouseEvent); this.addEventListener("dblclick", this._onMouseEvent); this.addEventListener("keydown", this._onKeyDown); this.addEventListener("keypress", this._onKeyPress); this.addEventListener("focus", this._onFocusChange); this.addEventListener("blur", this._onFocusChange); this._selectionModel.addEventListener("change", function(e) { this.dispatchEvent(new BiEvent("change")); } , this); this.add(this._headers); this._headers.addEventListener("columnwidthschanged", this.updateColumns, this); this._headers.addEventListener("columnorderschanged", function(e) { this.setColumnOrders(this._headers.getColumnOrders()); this.updateColumns(); this.updateData(); }, this); this._headers.addEventListener("sortcolumnchanged", function(e) { this.sort(this._headers.getSortColumn(), this._headers.getAscending()); } , this); this._headers.addEventListener("ascendingchanged", function(e) { this.sort(this._headers.getSortColumn(), this._headers.getAscending()); } , this); this.addEventListener("scroll", function(e) { this._headers.setScrollLeft(this.getScrollLeft()); } );}var _p = BiTree.prototype = new BiAbstractGrid;_p._className = "BiTree";BiTree.I_ICON = application.getPath() + "images/I.gif";BiTree.L_ICON = application.getPath() + "images/L.gif";BiTree.T_ICON = application.getPath() + "images/T.gif";BiTree.I_PLUS_ICON = application.getPath() + "images/Iplus.gif";BiTree.L_PLUS_ICON = application.getPath() + "images/Lplus.gif";BiTree.T_PLUS_ICON = application.getPath() + "images/Tplus.gif";BiTree.I_MINUS_ICON = application.getPath() + "images/Iminus.gif";BiTree.L_MINUS_ICON = application.getPath() + "images/Lminus.gif";BiTree.T_MINUS_ICON = application.getPath() + "images/Tminus.gif";BiTree.MINUS_ICON = application.getPath() + "images/minus.gif";BiTree.PLUS_ICON = application.getPath() + "images/plus.gif";BiTree.DEFAULT_ICON = application.getPath() + "images/file.gif";BiTree.BLANK_ICON = application.getPath() + "images/blank.gif";new BiImagePreloader(BiTree.I_ICON);new BiImagePreloader(BiTree.L_ICON);new BiImagePreloader(BiTree.T_ICON);new BiImagePreloader(BiTree.I_PLUS_ICON);new BiImagePreloader(BiTree.L_PLUS_ICON);new BiImagePreloader(BiTree.T_PLUS_ICON);new BiImagePreloader(BiTree.I_MINUS_ICON);new BiImagePreloader(BiTree.L_MINUS_ICON);new BiImagePreloader(BiTree.T_MINUS_ICON);new BiImagePreloader(BiTree.MINUS_ICON);new BiImagePreloader(BiTree.PLUS_ICON);new BiImagePreloader(BiTree.DEFAULT_ICON);new BiImagePreloader(BiTree.BLANK_ICON);_p._indentColumn = -1;_p._indentWidth = 19;_p._showLines = true;_p._showRootLines = false;_p._showPlusMinus = true;_p._parentNode = null;_p._rowHeight = 16;BiTree.prototype.getIndentWidth = function(){ return this._indentWidth;} ;BiTree.prototype.setIndentWidth = function(v){ this._indentWidth = v;} ;BiTree.prototype.getShowPlusMinus = function(){ return this._showPlusMinus;} ;BiTree.prototype.setShowPlusMinus = function(v){ this._showPlusMinus = v;} ;BiTree.prototype.getShowRootLines = function(){ return this._showRootLines;} ;BiTree.prototype.setShowRootLines = function(v){ this._showRootLines = v;} ;_p._layoutHeadersX = function(){ this._gridBodyElement.style.width = this._element.clientWidth + "px"; this.updateHeadersWidth();};_p._layoutHeadersY = function(){ this._gridBodyElement.style.height = this._element.clientHeight + "px";} ;_p.addNode = function(oChild, oBefore){ var p = oChild._parentNode; if (oBefore == null) { if (p != null) p.removeNode(oChild); this._nodes.push(oChild); } else { if (oBefore._parentNode != this) throw new Error("Can only add components before siblings"); if (p != null) p.removeNode(oChild); this._nodes.insertBefore(oChild, oBefore); this._rows = this._nodes; } oChild._parentNode = this; oChild._grid = this; oChild._level = 1; this._clearCache();};_p.removeNode = function(oChild){ if (oChild._parentNode != this) throw new Error("Can only remove children"); this._nodes.remove(oChild); this._rows = this._nodes; oChild._parentNode = null; oChild._grid = null; this._clearCache(); return oChild;};_p.getGrid = _p.getTree = function(){ return this;} ;_p.getLevel = function(){ return -1;} ;_p.containsNode = function(oDescendant){ if (oDescendant == null) return false; if (oDescendant == this) return true; var p = oDescendant._parentNode; return this.containsNode(p);};_p.getFirstNode = function(){ return this._nodes[0];} ;_p.getLastNode = function(){ return this._nodes[this._nodes.length - 1];} ;BiTree.prototype.getNodes = function(){ return this._nodes;} ;_p.hasNodes = function(){ return this._nodes.length > 0;} ;_p.isLeaf = function(){ return !this.hasNodes();} ;_p.getNextSiblingNode = function(){ return null;} ;_p.getPreviousSiblingNode = function(){ return null;} ;_p.isLastSiblingNode = function(){ return true;} ;_p.getParentNode = function(){ return null;} ;_p.removeAll = function(){ this._selectionModel.deselectAll(); for (var i = this._nodes.length - 1; i >= 0; i--) { var n = this._nodes[i]; this.removeNode(n); n.dispose(); }};BiTree.prototype.getIndentColumn = function(){ return this._indentColumn;} ;_p.setIndentColumn = function(n){ if (this._columns[this._indentColumn]) this._columns[this._indentColumn]._indentColumn = false; this._indentColumn = n; if (this._columns[this._indentColumn]) this._columns[this._indentColumn]._indentColumn = true;};BiTree.prototype.setShowLines = function(v){ this._showLines = v;} ;_p.getShowLines = function(){ return this._showLines && this._indentColumn >= 0 && this._indentColumn < this._columnCount;} ;_p._getStyleRules = function(){ var rs = []; var id = this.getHtmlProperty("id"); var align; var widthSum = 0; for (var i = 0; i < this._columnCount; i++) { align = this._columnAligns[i]; rs.push({ selector: "#" + id + " .col-" + i, style: "width:" + this._columnWidths[i] + "px" + (align != "left" ? ";text-align:" + align : "") }); widthSum += this._columnWidths[i]; } if (this._indentColumn != -1 && this._indentColumn < this._columnCount) { if (this._showPlusMinus || this._showLines) rs.push({ selector: "#" + id + " .col-" + this._indentColumn, style: "padding-left:0" }); var indentColumnLeft = 0; var visIndex = this._columns[this._indentColumn].getOrderIndex(); for (var i = 0; i < this._columnCount; i++) { if (this._columns[i].getOrderIndex() < visIndex) indentColumnLeft += this._columnWidths[i]; } var accumSelector = "#" + id + " .bi-tree-children "; var accumPadding = this._indentWidth + (this._showPlusMinus || this._showLines ? 0 : 5); var d = this.getDepth(); for (var i = 1; i < d; i++) { rs.push({ selector: accumSelector + ".col-" + this._indentColumn, style: "padding-left:" + accumPadding + "px" }); if (accumPadding - Math.ceil(this._indentWidth / 2) > this._columnWidths[this._indentColumn]) break; rs.push({ selector: accumSelector, style: "background-position:" + (accumPadding + indentColumnLeft - this._indentWidth) + "px 0" }); accumPadding += this._indentWidth; accumSelector += ".bi-tree-children "; } } var val = "height:" + this._rowHeight + "px;" + "line-height:" + (this._rowHeight - 2) + "px;" + "font-size:" + this._fontSize + "px;"; rs.push({ selector: "#" + id + " .bi-tree-cell", style: val }); rs.push({ selector: "#" + id + " .bi-tree-row", style: val }); rs.push({ selector: "#" + id + " .bi-tree-row", style: "width:" + widthSum + "px;" }); return rs;};_p.getDepth = function(){ if (this._depth != null) return this._depth; var d = 0; var cs = this._nodes; var l = cs.length; for (var i = 0; i < l; i++) d = Math.max(d, cs[i].getDepth() + 1); return this._depth = d;};_p._findItem = function(oValue, nStartIndex, sType){ var i; var items = BiTreeHelper.getPreorderShownNodes(this); if (nStartIndex == null) { var si = this.getSelectedNode(); nStartIndex = items.indexOf(si); if (nStartIndex == -1) nStartIndex = 0; } var methodName = "matches" + sType; for (i = nStartIndex; i < items.length; i++) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -