📄 gridrenderer.js
字号:
canFocus:true//>Animation// If a px / second speed is specified for a row animation, cap it at a maximum// (Inherited from LG / TG if specified there),animateRowsMaxTime:1000,//<Animation//> @attr gridRenderer.snapToCells (boolean : false : IRW)// Should drag-and-drop operations snap the dragged object into line with the nearest cell?//// @group dragdrop// @visibility external//<snapToCells: false, //> @attr gridRenderer.snapInsideBorder (boolean : false : IRW)// If true, snap-to-cell drops will snap the dropped object inside the selected cell's border.// If false, snap-to-cell drops will snap the dropped object to the edge of the selected cell, // regardless of borders//// @group dragdrop// @see GridRenderer.snapToCells// @visibility external//<snapInsideBorder: false,snapHDirection: isc.Canvas.BEFORE,snapVDirection: isc.Canvas.BEFORE});isc.GridRenderer.addMethods({initWidget : function () { // Make sure we have columnWidths set up - we rely on this for some methods if (!this._fieldWidths) this.setColumnWidths([]); if (this.selection) this.setSelection(this.selection); // If we're overflow visible, we have to write out our entire body content. if (this.overflow == isc.Canvas.VISIBLE) { this.showAllRows = true; this.showAllColumns = true; } if (!this.fixedRowHeights && !this.showAllRows) { // set average row height, if unset, to a typical row height given a few lines of // wrapping text if (!this.avgRowHeight) this.avgRowHeight = 60; if (this.virtualScrolling == null) this.virtualScrolling = true; this._avoidRedrawFlash = true; if (this.showCustomScrollbars == false) { this.logWarn("Variable height records cannot be used with native scrollbars;" + " set showCustomScrollbars:true globally or on this GridRenderer"); } // have to force rendering all columns, otherwise, row heights would vary with drawn // columns. this.showAllColumns = true; } this.avgRowHeight = this.avgRowHeight || this.cellHeight; if (this.fastCellUpdates && !isc.Browser.isIE) this.fastCellUpdates = false; },// Empty Message handling// --------------------------------------------------------------------------------------------isEmpty : function () { return false; }, _showEmptyMessage : function () { return this.getEmptyMessageHTML();},//> @method gridRenderer.getEmptyMessageHTML() ([A])// Return the HTML to show if there's nothing in the list// @group drawing// @return (string) HTML for the empty message layer//<getEmptyMessageHTML : function () { if (!this.showEmptyMessage) return " "; return isc.StringBuffer.concat( "<TABLE BORDER=0 MARGIN=0 CELLSPACING=0 CLASS='",this.emptyMessageTableStyle, "' style='width:",this.getViewportWidth(),"px;", (isc.Browser.isSafari ? "height" + this.getViewportHeight() + ":px;'" : "' HEIGHT=100%"), "><TR><TD ALIGN=CENTER VALIGN=TOP CLASS='", this.emptyMessageStyle, // NOTE: empty message can't be too tall, or it will introduce vscrolling in // shorter grids "'>", this.getEmptyMessage(), "</TD></TR></TABLE>" );},//> @method gridRenderer.getEmptyMessage() ([A])// @group drawing// return the text for the empty message// you can ovveride this function if your data has additional semantics// (eg: initial conditions, loading, filtering, etc)// @return (string) empty message//<getEmptyMessage : function () { return this.emptyMessage;},// Drawing// --------------------------------------------------------------------------------------------getInnerHTML : function () { return this.getTableHTML();}, shouldUseQuickDrawAheadRatio : function () { return this.useQuickDrawAheadRatio || this.isDragScrolling() || this.isRepeatTrackScrolling();},doneFastScrolling : function () { // if our last redraw was caused by fast scrolling we will have applied the quick // draw ahead ratio when determining which records to draw. In this case we now want // to redraw with the standard drawAhead ratio so short distance scrolls around this area // will requrie fewer redraws var redrawRequired = this._appliedQuickDrawAhead; if (redrawRequired) { // set the flag to suppress drawAhead direction calculation. This ensures that we // add draw-ahead rows in all directions on the theory that the user is done scrolling // large increments in one direction. // We clear this flag when the delayed redraw() actually fires this._suppressDrawAheadDirection = true; this.markForRedraw("Done Fast scrolling."); }},// given a range elements (rows or cols) currently visible in the viewport, apply the// drawAheadRatio to determine the range to draw. The "drawAheadRatio" is a fraction (>1) of// the viewport. "scrollForward" is the scrolling direction: true (forward), false (backward),// or null (unknown)addDrawAhead : function (startIndex, endIndex, maxIndex, scrollForward, vertical) { // figure out how many elements we intend to draw var useQuickDrawAhead = this.shouldUseQuickDrawAheadRatio(), ratio = useQuickDrawAhead && this.quickDrawAheadRatio != null ? this.quickDrawAheadRatio : this.drawAheadRatio, numToDraw = Math.ceil((endIndex - startIndex) * ratio); // respect the flag to suppress the drawAhead scrolling direction logic if (this._suppressDrawAheadDirection) scrollForward = null; if (scrollForward != null) { // we know the scroll direction; render extra elements in the current direction of // scrolling if (scrollForward) endIndex = startIndex + numToDraw; else startIndex = endIndex - numToDraw; } else { // we haven't been scrolled yet; if we're flush at the beginning (very common), render // ahead forward if (startIndex == 0) endIndex = numToDraw; else { // otherwise, render extra rows on either side var extraElements = Math.ceil((numToDraw - (endIndex - startIndex))/2); startIndex -= extraElements; endIndex += extraElements; } } // clamp ends of the range to 0 / maxIndex if (startIndex < 0) { // shift both ends of the range forward so startIndex = 0 endIndex -= startIndex; startIndex = 0; } if (endIndex >= maxIndex) { // shift both ends of the range back so endIndex < maxIndex var offset = endIndex - (maxIndex -1); startIndex = Math.max(0, (startIndex - offset)); endIndex = Math.max(0, maxIndex - 1); } // store a flag indicating whether this redraw used the special 'quick draw ahead' code // this is checked in doneFastScrolling to determine whether a redraw is required. if (useQuickDrawAhead) this._appliedQuickDrawAhead = true; else delete this._appliedQuickDrawAhead; return [startIndex, endIndex];},getExtraRowHeight : function (startRow, endRow) { var total = 0; for (var rowNum = startRow; rowNum < endRow; rowNum++) { var height = this.getRowHeight(this.getCellRecord(rowNum, 0), rowNum), extraHeight = (height - this.cellHeight); if (extraHeight > 0) { //this.logWarn("rowNum: " + rowNum + // " in range: " + [this._firstDrawnRow, this._lastDrawnRow] + // " with extraHeight: " + extraHeight); total += extraHeight; } } return total;},getDrawArea : function (colNum) { // Figure out what rows should be drawn // -------------------------------------------------------------------------------------------- var totalRows = this.getTotalRows(), startRow, endRow, vScrollForward; if (this.showAllRows) { // draw all rows startRow = 0; endRow = totalRows - 1; } else { // ordinary incremental rendering // figure out which rows we need to draw to minimally fill the viewport var visibleRows = this._getViewportFillRows(); // detect scrolling direction: true (forward), false (backward), or null (unknown) vScrollForward = (this.lastScrollTop == null ? null : this.lastScrollTop < this.getScrollTop()); //this.logWarn("viewportFillRows: " + visibleRows); // Note: addDrawAhead will add the draw-ahead rows (rows drawn offscreen for // scrolling), and clamp the ends of the drawn range to the ends of the data (ensuring // we don't end up with startRow < 0, or endRow > (totalRows-1) var drawAheadRange = this.addDrawAhead(visibleRows[0], visibleRows[1], totalRows, vScrollForward, true); //this.logWarn("after adding drawAhead:" + drawAheadRange); startRow = drawAheadRange[0]; endRow = drawAheadRange[1]; } // Figure out which columns to draw // -------------------------------------------------------------------------------------------- var startCol, endCol, totalCols = this.fields.length, hScrollForward; if (colNum != null) { // a column number was specified, draw that column only (needed for legacy Nav4 support, and // for column auto-sizing) startCol = colNum; endCol = colNum + 1; } else if (this.showAllColumns) { // draw all columns startCol = 0; endCol = totalCols - 1; } else { // incremental rendering var visibleColumns = this.getVisibleColumns(); // detect scrolling direction: true (forward), false (backward), or null (unknown) hScrollForward = (this.lastScrollLeft == null ? null : this.lastScrollLeft < this.getScrollLeft()); var drawAheadRange = this.addDrawAhead(visibleColumns[0], visibleColumns[1], totalCols, hScrollForward); startCol = drawAheadRange[0]; endCol = drawAheadRange[1]; } // figure out the appropriate chunk size on first draw ever if (this.cacheDOM && !this._rowChunkSize) { this._rowChunkSize = endRow - startRow; this._colChunkSize = endCol - startCol; } return [startRow, endRow, startCol, endCol];}, // get the row at the coordinate, as a floating point number representing a partial distance// through the rowgetRowCoordinate : function (coord) { var rowNum = this.getEventRow(coord), // get our offset into it rowTop = this.getRowTop(rowNum), offsetIntoRow = coord - rowTop, rowHeight = this.getRowSize(rowNum), percentIntoRow = offsetIntoRow / rowHeight; // detect inconsistency between getEventRow and getRowTop() //if (offsetIntoRow < 0 || offsetIntoRow > rowHeight) { // this.logWarn("*******************************\n" + // ", coord: " + coord + // ", eventRow: " + rowNum + // ", rowTop: " + rowTop + // ", offsetIntoRow: " + offsetIntoRow + // ", rowSize: " + rowHeight + // ", firstDrawn: " + this._firstDrawnRow + // ", lastDrawn: " + this._lastDrawnRow + // ", heights: " + this._getDrawnRowHeights()); //} return rowNum + percentIntoRow;},// override to interpret ratio in terms of rowNum instead of scrollTop vs scrollHeightscrollToRatio : function (vertical, ratio,a,b) { if (!vertical || !this.virtualScrolling) { return this.invokeSuper(isc.GridRenderer, "scrollToRatio", vertical,ratio,a,b); } var maxRow = this.getTotalRows() - 1, exactRowNum = ratio * maxRow, rowNum = Math.floor(exactRowNum), rowOffset = Math.round((exactRowNum - rowNum) * this.getRowSize(rowNum)); this._targetRow = rowNum; this._rowOffset = rowOffset; this._scrollToTargetRow(); // if scrolling to that position makes us dirty, setup to scroll to the indicated target // row during redraw if (this.isDirty()) { this._scrollRatio = ratio; this._targetRow = rowNum; this._rowOffset = rowOffset; }},
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -