📄 virtualgrid.js
字号:
if(!this.domNode){return;} if(!this.hasLayout()) { this.scroller.init(0, this.keepRows, this.rowsPerPage); return; } // this.update = this.defaultUpdate; this.scroller.init(this.rowCount, this.keepRows, this.rowsPerPage); this.prerender(); this.setScrollTop(0); this.postrender(); }, prerender: function(){ // if autoHeight, make sure scroller knows not to virtualize; everything must be rendered. this.keepRows = this.autoHeight ? 0 : this.constructor.prototype.keepRows; this.scroller.setKeepInfo(this.keepRows); this.views.render(); this._resize(); }, postrender: function(){ this.postresize(); this.focus.initFocusView(); // make rows unselectable dojo.setSelectable(this.domNode, false); }, postresize: function(){ // views are position absolute, so they do not inflate the parent if(this.autoHeight){ this.viewsNode.style.height = this.views.measureContent() + 'px'; } }, renderRow: function(inRowIndex, inNodes){ // summary: private, used internally to render rows this.views.renderRow(inRowIndex, inNodes); }, rowRemoved: function(inRowIndex){ // summary: private, used internally to remove rows this.views.rowRemoved(inRowIndex); }, invalidated: null, updating: false, beginUpdate: function(){ // summary: // Use to make multiple changes to rows while queueing row updating. // NOTE: not currently supporting nested begin/endUpdate calls this.invalidated = []; this.updating = true; }, endUpdate: function(){ // summary: // Use after calling beginUpdate to render any changes made to rows. this.updating = false; var i = this.invalidated; if(i.all){ this.update(); }else if(i.rowCount != undefined){ this.updateRowCount(i.rowCount); }else{ for(r in i){ this.updateRow(Number(r)); } } this.invalidated = null; }, // update defaultUpdate: function(){ // note: initial update calls render and subsequently this function. if(!this.domNode){return;} if(this.updating){ this.invalidated.all = true; return; } //this.edit.saveState(inRowIndex); this.prerender(); this.scroller.invalidateNodes(); this.setScrollTop(this.scrollTop); this.postrender(); //this.edit.restoreState(inRowIndex); }, update: function(){ // summary: // Update the grid, retaining edit and scrolling states. this.render(); }, updateRow: function(inRowIndex){ // summary: // Render a single row. // inRowIndex: Integer // Index of the row to render inRowIndex = Number(inRowIndex); if(this.updating){ this.invalidated[inRowIndex]=true; }else{ this.views.updateRow(inRowIndex, this.rows.getHeight(inRowIndex)); this.scroller.rowHeightChanged(inRowIndex); } }, updateRowCount: function(inRowCount){ //summary: // Change the number of rows. // inRowCount: int // Number of rows in the grid. if(this.updating){ this.invalidated.rowCount = inRowCount; }else{ this.rowCount = inRowCount; if(this.layout.cells.length){ this.scroller.updateRowCount(inRowCount); this.setScrollTop(this.scrollTop); } this._resize(); } }, updateRowStyles: function(inRowIndex){ // summary: // Update the styles for a row after it's state has changed. this.views.updateRowStyles(inRowIndex); }, rowHeightChanged: function(inRowIndex){ // summary: // Update grid when the height of a row has changed. Row height is handled automatically as rows // are rendered. Use this function only to update a row's height outside the normal rendering process. // inRowIndex: Integer // index of the row that has changed height this.views.renormalizeRow(inRowIndex); this.scroller.rowHeightChanged(inRowIndex); }, // fastScroll: Boolean // flag modifies vertical scrolling behavior. Defaults to true but set to false for slower // scroll performance but more immediate scrolling feedback fastScroll: true, delayScroll: false, // scrollRedrawThreshold: int // pixel distance a user must scroll vertically to trigger grid scrolling. scrollRedrawThreshold: (dojo.isIE ? 100 : 50), // scroll methods scrollTo: function(inTop){ // summary: // Vertically scroll the grid to a given pixel position // inTop: Integer // vertical position of the grid in pixels if(!this.fastScroll){ this.setScrollTop(inTop); return; } var delta = Math.abs(this.lastScrollTop - inTop); this.lastScrollTop = inTop; if(delta > this.scrollRedrawThreshold || this.delayScroll){ this.delayScroll = true; this.scrollTop = inTop; this.views.setScrollTop(inTop); dojox.grid.jobs.job('dojoxGrid-scroll', 200, dojo.hitch(this, "finishScrollJob")); }else{ this.setScrollTop(inTop); } }, finishScrollJob: function(){ this.delayScroll = false; this.setScrollTop(this.scrollTop); }, setScrollTop: function(inTop){ this.scrollTop = this.views.setScrollTop(inTop); this.scroller.scroll(this.scrollTop); }, scrollToRow: function(inRowIndex){ // summary: // Scroll the grid to a specific row. // inRowIndex: Integer // grid row index this.setScrollTop(this.scroller.findScrollTop(inRowIndex) + 1); }, // styling (private, used internally to style individual parts of a row) styleRowNode: function(inRowIndex, inRowNode){ if(inRowNode){ this.rows.styleRowNode(inRowIndex, inRowNode); } }, // cells getCell: function(inIndex){ // summary: // Retrieves the cell object for a given grid column. // inIndex: Integer // Grid column index of cell to retrieve // returns: // a grid cell return this.layout.cells[inIndex]; }, setCellWidth: function(inIndex, inUnitWidth) { this.getCell(inIndex).unitWidth = inUnitWidth; }, getCellName: function(inCell){ // summary: Returns the cell name of a passed cell return "Cell " + inCell.index; // String }, // sorting canSort: function(inSortInfo){ // summary: // Determines if the grid can be sorted // inSortInfo: Integer // Sort information, 1-based index of column on which to sort, positive for an ascending sort // and negative for a descending sort // returns: Boolean // True if grid can be sorted on the given column in the given direction }, sort: function(){ }, getSortAsc: function(inSortInfo){ // summary: // Returns true if grid is sorted in an ascending direction. inSortInfo = inSortInfo == undefined ? this.sortInfo : inSortInfo; return Boolean(inSortInfo > 0); // Boolean }, getSortIndex: function(inSortInfo){ // summary: // Returns the index of the column on which the grid is sorted inSortInfo = inSortInfo == undefined ? this.sortInfo : inSortInfo; return Math.abs(inSortInfo) - 1; // Integer }, setSortIndex: function(inIndex, inAsc){ // summary: // Sort the grid on a column in a specified direction // inIndex: Integer // Column index on which to sort. // inAsc: Boolean // If true, sort the grid in ascending order, otherwise in descending order var si = inIndex +1; if(inAsc != undefined){ si *= (inAsc ? 1 : -1); } else if(this.getSortIndex() == inIndex){ si = -this.sortInfo; } this.setSortInfo(si); }, setSortInfo: function(inSortInfo){ if(this.canSort(inSortInfo)){ this.sortInfo = inSortInfo; this.sort(); this.update(); } }, // DOM event handler doKeyEvent: function(e){ e.dispatch = 'do' + e.type; this.onKeyEvent(e); }, // event dispatch //: protected _dispatch: function(m, e){ if(m in this){ return this[m](e); } }, dispatchKeyEvent: function(e){ this._dispatch(e.dispatch, e); }, dispatchContentEvent: function(e){ this.edit.dispatchEvent(e) || e.sourceView.dispatchContentEvent(e) || this._dispatch(e.dispatch, e); }, dispatchHeaderEvent: function(e){ e.sourceView.dispatchHeaderEvent(e) || this._dispatch('doheader' + e.type, e); }, dokeydown: function(e){ this.onKeyDown(e); }, doclick: function(e){ if(e.cellNode){ this.onCellClick(e); }else{ this.onRowClick(e); } }, dodblclick: function(e){ if(e.cellNode){ this.onCellDblClick(e); }else{ this.onRowDblClick(e); } }, docontextmenu: function(e){ if(e.cellNode){ this.onCellContextMenu(e); }else{ this.onRowContextMenu(e); } }, doheaderclick: function(e){ if(e.cellNode){ this.onHeaderCellClick(e); }else{ this.onHeaderClick(e); } }, doheaderdblclick: function(e){ if(e.cellNode){ this.onHeaderCellDblClick(e); }else{ this.onHeaderDblClick(e); } }, doheadercontextmenu: function(e){ if(e.cellNode){ this.onHeaderCellContextMenu(e); }else{ this.onHeaderContextMenu(e); } }, // override to modify editing process doStartEdit: function(inCell, inRowIndex){ this.onStartEdit(inCell, inRowIndex); }, doApplyCellEdit: function(inValue, inRowIndex, inFieldIndex){ this.onApplyCellEdit(inValue, inRowIndex, inFieldIndex); }, doCancelEdit: function(inRowIndex){ this.onCancelEdit(inRowIndex); }, doApplyEdit: function(inRowIndex){ this.onApplyEdit(inRowIndex); }, // row editing addRow: function(){ // summary: // Add a row to the grid. this.updateRowCount(this.rowCount+1); }, removeSelectedRows: function(){ // summary: // Remove the selected rows from the grid. this.updateRowCount(Math.max(0, this.rowCount - this.selection.getSelected().length)); this.selection.clear(); }});dojo.mixin(dojox.VirtualGrid.prototype, dojox.grid.publicEvents);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -