📄 bufferedgridview.js
字号:
/* * Ext.ux.grid.BufferedGridView V0.1 * Copyright(c) 2007, http://www.siteartwork.de * * Licensed under the terms of the Open Source LGPL 3.0 * http://www.gnu.org/licenses/lgpl.html * * @author Thorsten Suckow-Homberg <ts@siteartwork.de> *//** * @class Ext.ux.grid.BufferedGridView * @extends Ext.grid.GridView * * * @constructor * @param {Object} config */Ext.namespace('Ext.ux.grid');Ext.ux.grid.BufferedGridView = function(config) { this.addEvents({ /** * @event beforebuffer * Fires when the store is about to buffer new data. * @param {Ext.ux.BufferedGridView} this * @param {Ext.data.Store} store The store * @param {Number} rowIndex * @param {Number} visibleRows * @param {Number} totalCount */ 'beforebuffer' : true, /** * @event buffer * Fires when the store is finsihed buffering new data. * @param {Ext.ux.BufferedGridView} this * @param {Ext.data.Store} store The store * @param {Number} rowIndex * @param {Number} visibleRows * @param {Number} totalCount */ 'buffer' : true, /** * @event cursormove * Fires when the the user scrolls through the data. * @param {Ext.ux.BufferedGridView} this * @param {Number} rowIndex The index of the first visible row in the * grid absolute to it's position in the model. * @param {Number} visibleRows The number of rows visible in the grid. * @param {Number} totalCount */ 'cursormove' : true }); /** * @cfg {Number} bufferSize The number of records that will at least always * be available in the store for rendering. This value will be send to the * server as the <tt>limit</tt> parameter and should not change during the * lifetime of a grid component. Note: In a paging grid, this number would * indicate the page size. * The value should be set high enough to make a userfirendly scrolling * possible and should be greater than the sum of {nearLimit} and * {visibleRows}. Usually, a value in between 150 and 200 is good enough. * A lesser value will more often make the store re-request new data, while * a larger number will make loading times higher. */ /** * @cfg {Number} nearLimit This value represents a near value that is responsible * for deciding if a request for new data is needed. The lesser the number, the * more often new data will be requested. The number should be set to a value * that lies in between 1/4 to 1/2 of the {bufferSize}. */ /** * @cfg {Number} horizontalScrollOffset The height of a horizontal aligned * scrollbar. The scrollbar is shown if the total width of all visible * columns exceeds the width of the grid component. * On Windows XP (IE7, FF2), this value defaults to 16. */ this.horizontalScrollOffset = 16; /** * @cfg {Object} loadMaskConfig The config of the load mask that will be shown * by the view if a request for new data is underway. */ this.loadMask = false; Ext.apply(this, config); /** * The array represents the range of rows available in the buffer absolute to * the indexes of the data model. * @param {Array} */ this.bufferRange = [0, -1]; this.templates = {}; /** * The master template adds an addiiotnal scrollbar to make cursoring in the * data possible. */ this.templates.master = new Ext.Template( '<div class="x-grid3" hidefocus="true"><div style="z-index:2000;background:none;position:relative;height:321px; float:right; width: 18px;overflow: scroll;"><div style="background:none;width:1px;overflow:hidden;font-size:1px;height:0px;"></div></div>', '<div class="x-grid3-viewport" style="float:left">', '<div class="x-grid3-header"><div class="x-grid3-header-inner"><div class="x-grid3-header-offset">{header}</div></div><div class="x-clear"></div></div>', '<div class="x-grid3-scroller" style="overflow-y:hidden !important;"><div class="x-grid3-body" style="position:relative;">{body}</div><a href="#" class="x-grid3-focus" tabIndex="-1"></a></div>', "</div>", '<div class="x-grid3-resize-marker"> </div>', '<div class="x-grid3-resize-proxy"> </div>', "</div>" ); Ext.ux.grid.BufferedGridView.superclass.constructor.call(this);};Ext.extend(Ext.ux.grid.BufferedGridView, Ext.grid.GridView, {// {{{ --------------------------properties------------------------------------- /** * This is the actual y-scroller that does control sending request to the server * based upon the position of the scrolling cursor. * @param {Ext.Element} */ liveScroller : null, /** * This is the panel that represents the amount of data in a given repository. * The height gets computed via the total amount of records multiplied with * the fixed(!) row height * @param {native HTMLObject} */ liveScrollerInset : null, /** * The <b>fixed</b> row height for <b>every</b> row in the grid. The value is * computed once the store has been loaded for the first time and used for * various calculations during the lifetime of the grid component, such as * the height of the scroller and the number of visible rows. * @param {Number} */ rowHeight : -1, /** * Stores the number of visible rows that have to be rendered. * @param {Number} */ visibleRows : 1, /** * Stores the last offset relative to a previously scroll action. This is * needed for deciding wether the user scrolls up or down. * @param {Number} */ lastIndex : -1, /** * Stores the last visible row at position "0" in the table view before * a new scroll event was created and fired. * @param {Number} */ lastRowIndex : 0, /** * Stores the value of the <tt>liveScroller</tt>'s <tt>scrollTop</tt> DOM * property. * @param {Number} */ lastScrollPos : 0, /** * The current index of the row in the model that is displayed as the first * visible row in the view. * @param {Number} */ rowIndex : 0, /** * Set to <tt>true</tt> if the store is busy with loading new data. * @param {Boolean} */ isBuffering : false, /** * If a request for new data was made and the user scrolls to a new position * that lays not within the requested range of the new data, the queue will * hold the latest requested position. If the buffering succeeds and the value * of requestQueue is not within the range of the current buffer, data may be * re-requested. * * @param {Number} */ requestQueue : -1, /** * The view's own load mask that will be shown when a request to data was made * and there are no rows in the buffer left to render. * @see {loadMaskConfig} * @param {Ext.LoadMask} */ loadMask : null, /** * Set to <tt>true</tt> if a request for new data has been made while there * are still rows in the buffer that can be rendered before the request * finishes. * @param {Boolean} */ isPrebuffering : false,// }}}// {{{ --------------------------public API methods----------------------------- /** * Resets the view to display the first row in the data model. This will * change the scrollTop property of the scroller and may trigger a request * to buffer new data, if the row index "0" is not within the buffer range and * forceReload is set to true. * * @param {Boolean} forceReload <tt>true</tt> to reload the buffers contents, * othwerwise <tt>false</tt> */ reset : function(forceReload) { if (forceReload === false) { this.ds.modified = []; this.grid.selModel.clearSelections(true); this.rowIndex = 0; this.lastScrollPos = 0; this.lastRowIndex = 0; this.lastIndex = 0; this.bufferRange = [0, this.ds.bufferSize]; this.adjustScrollerPos(-this.liveScroller.dom.scrollTop, true); this.showLoadMask(false); this.refresh(true); //this.replaceLiveRows(0, true); this.fireEvent('cursormove', this, 0, Math.min(this.ds.totalLength, this.visibleRows), this.ds.totalLength); } else { var params = { start : 0, limit : this.ds.bufferSize }; var sInfo = this.ds.sortInfo; if (sInfo) { params.dir = sInfo.direction; params.sort = sInfo.field; } this.ds.load({ callback : function(){this.reset(false);}, scope : this, params : params }); } },// {{{ ------------adjusted methods for applying custom behavior---------------- /** * Overwritten so the {@link Ext.ux.grid.BufferedGridDragZone} can be used * with this view implementation. * * Since detaching a previously created DragZone from a grid panel seems to * be impossible, a little workaround will tell the parent implementation * that drad/drop is not enabled for this view's grid, and right after that * the custom DragZone will be created, if neccessary. */ renderUI : function() { var g = this.grid; var dEnabled = g.enableDragDrop || g.enableDrag; g.enableDragDrop = false; g.enableDrag = false; Ext.ux.grid.BufferedGridView.superclass.renderUI.call(this); var g = this.grid; g.enableDragDrop = dEnabled; g.enableDrag = dEnabled; if(dEnabled){ var dd = new Ext.ux.grid.BufferedGridDragZone(g, { ddGroup : g.ddGroup || 'GridDD' }); } if (this.loadMask) { this.loadMask = new Ext.LoadMask( this.mainBody.dom.parentNode.parentNode, this.loadMask ); } }, /** * The extended implementation attaches an listener to the beforeload * event of the store of the grid. It is guaranteed that the listener will * only be executed upon reloading of the store, sorting and initial loading * of data. When the store does "buffer", all events are suspended and the * beforeload event will not be triggered. * * @param {Ext.grid.GridPanel} grid The grid panel this view is attached to */ init: function(grid) { Ext.ux.grid.BufferedGridView.superclass.init.call(this, grid); this.bufferRange = [0, this.ds.bufferSize]; this.ds.on('beforeload', this.onBeforeLoad, this); }, /** * Only render the viewable rect of the table. The number of rows visible to * the user is defined in <tt>visibleRows</tt>. * This implementation does completely overwrite the parent's implementation. */ // private renderBody : function() { var markup = this.renderRows(0, this.visibleRows-1); return this.templates.body.apply({rows: markup}); }, /** * Inits the DOM native elements for this component. * The properties <tt>liveScroller</tt> and <tt>liveScrollerInset</tt> will * be respected as provided by the master template. * The <tt>scroll</tt> listener for the <tt>liverScroller</tt> will also be * added here as the <tt>mousewheel</tt> listener. * This method overwrites the parents implementation. */ // private initElements : function() { var E = Ext.Element; var el = this.grid.getGridEl().dom.firstChild; var cs = el.childNodes; this.el = new E(el); this.mainWrap = new E(cs[1]); // liveScroller and liveScrollerInset this.liveScroller = new E(cs[0]); this.liveScrollerInset = this.liveScroller.dom.firstChild; this.liveScroller.on('scroll', this.onLiveScroll, this); this.mainHd = new E(this.mainWrap.dom.firstChild); this.innerHd = this.mainHd.dom.firstChild; this.scroller = new E(this.mainWrap.dom.childNodes[1]); if(this.forceFit){ this.scroller.setStyle('overflow-x', 'hidden'); } this.mainBody = new E(this.scroller.dom.firstChild); // addd the mousewheel event to the table's body this.mainBody.on('mousewheel', this.handleWheel, this); this.focusEl = new E(this.scroller.dom.childNodes[1]); this.focusEl.swallowEvent("click", true); this.resizeMarker = new E(cs[2]); this.resizeProxy = new E(cs[3]); },
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -