⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bufferedstore.js

📁 extjs + mysql + java
💻 JS
📖 第 1 页 / 共 2 页
字号:
/* * Ext.ux.grid.BufferedStore V0.9 * 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> */Ext.namespace('Ext.ux.grid');/** * @class Ext.ux.grid.BufferedStore * @extends Ext.data.Store * * The BufferedGridSore is a special implementation of a Ext.data.Store. It is used * for loading chunks of data from the underlying data repository as requested * by the Ext.ux.BufferedGridView. It's size is limited to the config parameter * bufferSize and is thereby guaranteed to never hold more than this amount * of records in the store. * * Requesting selection ranges: * ---------------------------- * This store implementation has 2 Http-proxies: A data proxy for requesting data * from the server for displaying and another proxy to request pending selections: * Pending selections are represented by row indexes which have been selected but * which records have not yet been available in the store. The loadSelections method * will initiate a request to the data repository (same url as specified in the  * url config parameter for the store) to fetch the pending selections. The additional * parameter send to the server is the "ranges" parameter, which will hold a json  * encoded string representing ranges of row indexes to load from the data repository. * As an example, pending selections with the indexes 1,2,3,4,5,9,10,11,16 would * have to be translated to [1,5],[9,11],[16]. * Please note, that by indexes we do not understand (primary) keys of the data, * but indexes as represented by the view. To get the ranges of pending selections,  * you can use the getPendingSelections method of the BufferedRowSelectionModel, which  * should be used as the default selection model of the grid. * * Version-property: * ----------------- * This implementation does also introduce a new member called "version". The version * property will help you in determining if any pending selections indexes are still * valid or may have changed. This is needed to reduce the danger of data inconsitence * when you are requesting data from the server: As an example, a range of indexes must * be read from the server but may have been become invalid when the row represented * by the index is no longer available in teh underlying data store, caused by a * delete or insert operation. Thus, you have to take care of the version property * by yourself (server side) and change this value whenever a row was deleted or * inserted. You can specify the path to the version property in the BufferedJsonReader, * which should be used as the default reader for this store. If the store recognizes * a version change, it will fire the versionchange event. It is up to the user * to remove all selections which are pending, or use them anyway. * * Inserting data: * --------------- * Another thing to notice is the way a user inserts records into the data store. * A user should always provide a sortInfo for the grid, so the findInsertIndex * method can return a value that comes close to the value as it would have been * computed by the underlying store's sort algorithm. Whenever a record should be * added to the store, the insert index should be calculated and the used as the * parameter for the insert method. The findInsertIndex method will return a value  * that equals to Number.MIN_VALUE or Number.MAX_VALUE if the added record would not  * change the current state of the store. If that happens, this data is not available * in the store, and may be requested later on when a new request for new data is made. * * Sorting: * -------- * remoteSort will always be set to true, no matter what value the user provides * using the config object.  * * @constructor * Creates a new Store. * @param {Object} config A config object containing the objects needed for the Store to access data, * and read the data into Records. */Ext.ux.grid.BufferedStore = function(config) {        config = config || {};        // remoteSort will always be set to true.    config.remoteSort = true;        Ext.apply(this, config);        this.addEvents({         /**          * @event versionchange          * Fires when the version property has changed.          * @param {Ext.ux.BufferedGridStore} this          * @param {String} oldValue          * @param {String} newValue          */        'versionchange'        : true,         /**          * @event beforeselectionsload          * Fires before the store sends a request for ranges of records to          * the server.          * @param {Ext.ux.BufferedGridStore} this          * @param {Array} ranges          */        'beforeselectionsload' : true,         /**          * @event selectionsload          * Fires when selections have been loaded.          * @param {Ext.ux.BufferedGridStore} this          * @param {Array} records An array containing the loaded records from          * the server.          * @param {Array} ranges An array containing the ranges of indexes this          * records may represent.          */        'selectionsload'       : true            });        Ext.ux.grid.BufferedStore.superclass.constructor.call(this, config);            if(this.url && !this.selectionsProxy){        this.selectionsProxy = new Ext.data.HttpProxy({url: this.url});    }	};Ext.extend(Ext.ux.grid.BufferedStore, Ext.data.Store, {    /**     * The version of the data in the store. This value is represented by the     * versionProperty-property of the BufferedJsonReader.     * @property     */    version : null,         /**     * Inserts a record at the position as specified in index.     * If the index equals to Number.MIN_VALUE or Number.MAX_VALUE, the record will     * not be added to the store, but still fire the add-event to indicate that     * the set of data in the underlying store has been changed.     * If the index equals to 0 and the length of data in the store equals to     * bufferSize, the add-event will be triggered with Number.MIN_VALUE to      * indicate that a record has been prepended. If the index equals to      * bufferSize, the method will assume that the record has been appended and     * trigger the add event with index set to Number.MAX_VALUE.     *     * Note:     * -----     * The index parameter is not a view index, but a value in the range of      * [0, this.bufferSize].     *     */    insert : function(index, records)    {        records      = [].concat(records);        var cRecords = [];        var cCount   = this.bufferSize-1;        var pIndex   = (index == Number.MIN_VALUE || index == Number.MAX_VALUE) ? 0 : index;             this.totalLength += records.length;                if (index == Number.MIN_VALUE || index == Number.MAX_VALUE || index == this.bufferSize             || (index == 0 && this.getCount() == this.bufferSize)) {            var tIndex = (index == this.bufferSize)                          ? Number.MAX_VALUE                         : ((index == Number.MIN_VALUE || index == 0) ? Number.MIN_VALUE : Number.MAX_VALUE);                                     this.fireEvent("add", this, records, tIndex);            return;        }         for (var i = 0, max_i = records.length; i < max_i; i++) {            if (i + pIndex > cCount) {                break;            }            cRecords.push(records[i]);            }                        for(var i = 0, len = cRecords.length; i < len; i++){            // different from original impl, shift one up            this.data.insert(index+i, cRecords[i]);            cRecords[i].join(this);        }                while (this.getCount() > this.bufferSize) {            this.data.remove(this.data.last());        }                        this.fireEvent("add", this, cRecords, index);    },             /**     * Remove a Record from the Store and fires the remove event.     *     * If the record is not within the store, the method will try to guess it's      * index by calling findInsertIndex.     */    remove : function(record)    {        var index = this.data.indexOf(record);                if (index < 0) {            var ind = this.findInsertIndex(record);            this.totalLength -= 1;            if(this.pruneModifiedRecords){                this.modified.remove(record);            }            this.fireEvent("remove", this, record, ind);            return false;        }        this.data.removeAt(index);        if(this.pruneModifiedRecords){            this.modified.remove(record);        }                this.totalLength -= 1;        this.fireEvent("remove", this, record, index);        return true;    },    /**     * Remove all Records from the Store and fires the clear event.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -