X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/c930e9176a5a85509c5b0230e2bff5c22a591432..6746dc89c47ed01b165cc1152533605f97eb8e8d:/docs/source/Store.html diff --git a/docs/source/Store.html b/docs/source/Store.html index 4937025a..0867f5a1 100644 --- a/docs/source/Store.html +++ b/docs/source/Store.html @@ -1,1503 +1,159 @@ - -
-/** - * @class Ext.data.Store - * @extends Ext.util.Observable - *The Store class encapsulates a client side cache of {@link Ext.data.Record Record} - * objects which provide input data for Components such as the {@link Ext.grid.GridPanel GridPanel}, - * the {@link Ext.form.ComboBox ComboBox}, or the {@link Ext.DataView DataView}.
- *Retrieving Data
- *A Store object may access a data object using:
- *- *
- {@link #proxy configured implementation} of {@link Ext.data.DataProxy DataProxy}
- *- {@link #data} to automatically pass in data
- *- {@link #loadData} to manually pass in data
- *Reading Data
- *A Store object has no inherent knowledge of the format of the data object (it could be - * an Array, XML, or JSON). A Store object uses an appropriate {@link #reader configured implementation} - * of a {@link Ext.data.DataReader DataReader} to create {@link Ext.data.Record Record} instances from the data - * object.
- *Store Types
- *There are several implementations of Store available which are customized for use with - * a specific DataReader implementation. Here is an example using an ArrayStore which implicitly - * creates a reader commensurate to an Array data object.
- *- *-var myStore = new Ext.data.ArrayStore({ - fields: ['fullname', 'first'], - idIndex: 0 // id for each record will be the first element -}); - *
For custom implementations create a basic {@link Ext.data.Store} configured as needed:
- *- *-// create a {@link Ext.data.Record Record} constructor: -var rt = Ext.data.Record.create([ - {name: 'fullname'}, - {name: 'first'} -]); -var myStore = new Ext.data.Store({ - // explicitly create reader - reader: new Ext.data.ArrayReader( - { - idIndex: 0 // id for each record will be the first element - }, - rt // recordType - ) -}); - *
Load some data into store (note the data object is an array which corresponds to the reader):
- *- *-var myData = [ - [1, 'Fred Flintstone', 'Fred'], // note that id for the record is the first element - [2, 'Barney Rubble', 'Barney'] -]; -myStore.loadData(myData); - *
Records are cached and made available through accessor functions. An example of adding - * a record to the store:
- *- * @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. - * @xtype store - */ -Ext.data.Store = function(config){ - this.data = new Ext.util.MixedCollection(false); - this.data.getKey = function(o){ - return o.id; - }; - /** - * See the-var defaultData = { - fullname: 'Full Name', - first: 'First Name' -}; -var recId = 100; // provide unique id for the record -var r = new myStore.recordType(defaultData, ++recId); // create new record -myStore.{@link #insert}(0, r); // insert a new record into the store (also see {@link #add}) - *
{@link #baseParams corresponding configuration option}
- * for a description of this property. - * To modify this property see{@link #setBaseParam}
. - * @property - */ - this.baseParams = {}; - - // temporary removed-records cache - this.removed = []; - - if(config && config.data){ - this.inlineData = config.data; - delete config.data; - } - - Ext.apply(this, config); - - this.paramNames = Ext.applyIf(this.paramNames || {}, this.defaultParamNames); - - if(this.url && !this.proxy){ - this.proxy = new Ext.data.HttpProxy({url: this.url}); - } - // If Store is RESTful, so too is the DataProxy - if (this.restful === true && this.proxy) { - // When operating RESTfully, a unique transaction is generated for each record. - this.batch = false; - Ext.data.Api.restify(this.proxy); - } - - if(this.reader){ // reader passed - if(!this.recordType){ - this.recordType = this.reader.recordType; - } - if(this.reader.onMetaChange){ - this.reader.onMetaChange = this.onMetaChange.createDelegate(this); - } - if (this.writer) { // writer passed - this.writer.meta = this.reader.meta; - this.pruneModifiedRecords = true; - } - } - - /** - * The {@link Ext.data.Record Record} constructor as supplied to (or created by) the - * {@link Ext.data.DataReader Reader}. Read-only. - *If the Reader was constructed by passing in an Array of {@link Ext.data.Field} definition objects, - * instead of a Record constructor, it will implicitly create a Record constructor from that Array (see - * {@link Ext.data.Record}.{@link Ext.data.Record#create create} for additional details).
- *This property may be used to create new Records of the type held in this Store, for example:
- * @property recordType - * @type Function - */ - - if(this.recordType){ - /** - * A {@link Ext.util.MixedCollection MixedCollection} containing the defined {@link Ext.data.Field Field}s - * for the {@link Ext.data.Record Records} stored in this Store. Read-only. - * @property fields - * @type Ext.util.MixedCollection - */ - this.fields = this.recordType.prototype.fields; - } - this.modified = []; - - this.addEvents( - /** - * @event datachanged - * Fires when the data cache has changed in a bulk manner (e.g., it has been sorted, filtered, etc.) and a - * widget that is using this Store as a Record cache should refresh its view. - * @param {Store} this - */ - 'datachanged', - /** - * @event metachange - * Fires when this store's reader provides new metadata (fields). This is currently only supported for JsonReaders. - * @param {Store} this - * @param {Object} meta The JSON metadata - */ - 'metachange', - /** - * @event add - * Fires when Records have been {@link #add}ed to the Store - * @param {Store} this - * @param {Ext.data.Record[]} records The array of Records added - * @param {Number} index The index at which the record(s) were added - */ - 'add', - /** - * @event remove - * Fires when a Record has been {@link #remove}d from the Store - * @param {Store} this - * @param {Ext.data.Record} record The Record that was removed - * @param {Number} index The index at which the record was removed - */ - 'remove', - /** - * @event update - * Fires when a Record has been updated - * @param {Store} this - * @param {Ext.data.Record} record The Record that was updated - * @param {String} operation The update operation being performed. Value may be one of: - *-// create the data store -var store = new Ext.data.ArrayStore({ - autoDestroy: true, - fields: [ - {name: 'company'}, - {name: 'price', type: 'float'}, - {name: 'change', type: 'float'}, - {name: 'pctChange', type: 'float'}, - {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'} - ] -}); -store.loadData(myData); - -// create the Grid -var grid = new Ext.grid.EditorGridPanel({ - store: store, - colModel: new Ext.grid.ColumnModel({ - columns: [ - {id:'company', header: 'Company', width: 160, dataIndex: 'company'}, - {header: 'Price', renderer: 'usMoney', dataIndex: 'price'}, - {header: 'Change', renderer: change, dataIndex: 'change'}, - {header: '% Change', renderer: pctChange, dataIndex: 'pctChange'}, - {header: 'Last Updated', width: 85, - renderer: Ext.util.Format.dateRenderer('m/d/Y'), - dataIndex: 'lastChange'} - ], - defaults: { - sortable: true, - width: 75 - } - }), - autoExpandColumn: 'company', // match the id specified in the column model - height:350, - width:600, - title:'Array Grid', - tbar: [{ - text: 'Add Record', - handler : function(){ - var defaultData = { - change: 0, - company: 'New Company', - lastChange: (new Date()).clearTime(), - pctChange: 0, - price: 10 - }; - var recId = 3; // provide unique id - var p = new store.recordType(defaultData, recId); // create new record - grid.stopEditing(); - store.{@link #insert}(0, p); // insert a new record into the store (also see {@link #add}) - grid.startEditing(0, 0); - } - }] -}); - *
- */ - 'update', - /** - * @event clear - * Fires when the data cache has been cleared. - * @param {Store} this - */ - 'clear', - /** - * @event exception - *- Ext.data.Record.EDIT - Ext.data.Record.REJECT - Ext.data.Record.COMMIT - *
Fires if an exception occurs in the Proxy during a remote request. - * This event is relayed through the corresponding {@link Ext.data.DataProxy}. - * See {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#exception exception} - * for additional details. - * @param {misc} misc See {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#exception exception} - * for description. - */ - 'exception', -
/** - * @event beforeload - * Fires before a request is made for a new data object. If the beforeload handler returns - * false the {@link #load} action will be canceled. - * @param {Store} this - * @param {Object} options The loading options that were specified (see {@link #load} for details) - */ - 'beforeload', - /** - * @event load - * Fires after a new set of Records has been loaded. - * @param {Store} this - * @param {Ext.data.Record[]} records The Records that were loaded - * @param {Object} options The loading options that were specified (see {@link #load} for details) - */ - 'load', - /** - * @event loadexception - *This event is deprecated in favor of the catch-all
- *{@link #exception}
- * event instead.This event is relayed through the corresponding {@link Ext.data.DataProxy}. - * See {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#loadexception loadexception} - * for additional details. - * @param {misc} misc See {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#loadexception loadexception} - * for description. - */ - 'loadexception', -
/** - * @event beforewrite - * @param {DataProxy} this - * @param {String} action [Ext.data.Api.actions.create|update|destroy] - * @param {Record/Array[Record]} rs - * @param {Object} options The loading options that were specified. Editoptions.params
to add Http parameters to the request. (see {@link #save} for details) - * @param {Object} arg The callback's arg object passed to the {@link #request} function - */ - 'beforewrite', - /** - * @event write - * Fires if the server returns 200 after an Ext.data.Api.actions CRUD action. - * Success or failure of the action is available in theresult['successProperty']
property. - * The server-code might set thesuccessProperty
to false if a database validation - * failed, for example. - * @param {Ext.data.Store} store - * @param {String} action [Ext.data.Api.actions.create|update|destroy] - * @param {Object} result The 'data' picked-out out of the response for convenience. - * @param {Ext.Direct.Transaction} res - * @param {Record/Record[]} rs Store's records, the subject(s) of the write-action - */ - 'write' - ); - - if(this.proxy){ - this.relayEvents(this.proxy, ['loadexception', 'exception']); - } - // With a writer set for the Store, we want to listen to add/remove events to remotely create/destroy records. - if (this.writer) { - this.on({ - scope: this, - add: this.createRecords, - remove: this.destroyRecord, - update: this.updateRecord - }); - } - - this.sortToggle = {}; - if(this.sortField){ - this.setDefaultSort(this.sortField, this.sortDir); - }else if(this.sortInfo){ - this.setDefaultSort(this.sortInfo.field, this.sortInfo.direction); + + + + +The source code + + + + + + +/** + * @class Ext.grid.property.Store + * @extends Ext.data.Store + * A custom {@link Ext.data.Store} for the {@link Ext.grid.property.Grid}. This class handles the mapping + * between the custom data source objects supported by the grid and the {@link Ext.grid.property.Property} format + * used by the {@link Ext.data.Store} base class. + */ +Ext.define('Ext.grid.property.Store', { + + extend: 'Ext.data.Store', + + alternateClassName: 'Ext.grid.PropertyStore', + + uses: ['Ext.data.reader.Reader', 'Ext.data.proxy.Proxy', 'Ext.data.ResultSet', 'Ext.grid.property.Property'], + + /** + * Creates new property store. + * @param {Ext.grid.Grid} grid The grid this store will be bound to + * @param {Object} source The source data config object + */ + constructor : function(grid, source){ + var me = this; + + me.grid = grid; + me.source = source; + me.callParent([{ + data: source, + model: Ext.grid.property.Property, + proxy: me.getProxy() + }]); + }, + + // Return a singleton, customized Proxy object which configures itself with a custom Reader + getProxy: function() { + if (!this.proxy) { + Ext.grid.property.Store.prototype.proxy = Ext.create('Ext.data.proxy.Memory', { + model: Ext.grid.property.Property, + reader: this.getReader() + }); + } + return this.proxy; + }, + + // Return a singleton, customized Reader object which reads Ext.grid.property.Property records from an object. + getReader: function() { + if (!this.reader) { + Ext.grid.property.Store.prototype.reader = Ext.create('Ext.data.reader.Reader', { + model: Ext.grid.property.Property, + + buildExtractors: Ext.emptyFn, + + read: function(dataObject) { + return this.readRecords(dataObject); + }, + + readRecords: function(dataObject) { + var val, + propName, + result = { + records: [], + success: true + }; + + for (propName in dataObject) { + if (dataObject.hasOwnProperty(propName)) { + val = dataObject[propName]; + if (this.isEditableValue(val)) { + result.records.push(new Ext.grid.property.Property({ + name: propName, + value: val + }, propName)); + } + } + } + result.total = result.count = result.records.length; + return Ext.create('Ext.data.ResultSet', result); + }, + + // private + isEditableValue: function(val){ + return Ext.isPrimitive(val) || Ext.isDate(val); } - } - } - }, - - /** - * Calls the specified function for each of the {@link Ext.data.Record Records} in the cache. - * @param {Function} fn The function to call. The {@link Ext.data.Record Record} is passed as the first parameter. - * Returning false aborts and exits the iteration. - * @param {Object} scope (optional) The scope in which to call the function (defaults to the {@link Ext.data.Record Record}). - */ - each : function(fn, scope){ - this.data.each(fn, scope); - }, - - /** - * Gets all {@link Ext.data.Record records} modified since the last commit. Modified records are - * persisted across load operations (e.g., during paging). Note: deleted records are not - * included. See also {@link #pruneModifiedRecords} and - * {@link Ext.data.Record}{@link Ext.data.Record#markDirty markDirty}.. - * @return {Ext.data.Record[]} An array of {@link Ext.data.Record Records} containing outstanding - * modifications. To obtain modified fields within a modified record see - *{@link Ext.data.Record}{@link Ext.data.Record#modified modified}.. - */ - getModifiedRecords : function(){ - return this.modified; - }, - - // private - createFilterFn : function(property, value, anyMatch, caseSensitive){ - if(Ext.isEmpty(value, false)){ - return false; - } - value = this.data.createValueMatcher(value, anyMatch, caseSensitive); - return function(r){ - return value.test(r.data[property]); - }; - }, - - /** - * Sums the value of property for each {@link Ext.data.Record record} between start - * and end and returns the result. - * @param {String} property A field in each record - * @param {Number} start (optional) The record index to start at (defaults to 0) - * @param {Number} end (optional) The last record index to include (defaults to length - 1) - * @return {Number} The sum - */ - sum : function(property, start, end){ - var rs = this.data.items, v = 0; - start = start || 0; - end = (end || end === 0) ? end : rs.length-1; - - for(var i = start; i <= end; i++){ - v += (rs[i].data[property] || 0); - } - return v; - }, - - /** - * Filter the {@link Ext.data.Record records} by a specified property. - * @param {String} field A field on your records - * @param {String/RegExp} value Either a string that the field should begin with, or a RegExp to test - * against the field. - * @param {Boolean} anyMatch (optional) true to match any part not just the beginning - * @param {Boolean} caseSensitive (optional) true for case sensitive comparison - */ - filter : function(property, value, anyMatch, caseSensitive){ - var fn = this.createFilterFn(property, value, anyMatch, caseSensitive); - return fn ? this.filterBy(fn) : this.clearFilter(); - }, - - /** - * Filter by a function. The specified function will be called for each - * Record in this Store. If the function returns true the Record is included, - * otherwise it is filtered out. - * @param {Function} fn The function to be called. It will be passed the following parameters:
The {@link Ext.data.Record record} - * to test for filtering. Access field values using {@link Ext.data.Record#get}.
The ID of the Record passed.
The {@link Ext.data.Record record} - * to test for filtering. Access field values using {@link Ext.data.Record#get}.
The ID of the Record passed.
The {@link Ext.data.Record record} - * to test for filtering. Access field values using {@link Ext.data.Record#get}.
The ID of the Record passed.
-myStore.setBaseParam('foo', {bar:3});
-
- * @param {String} name Name of the property to assign
- * @param {Mixed} value Value to assign the named property
- **/
- setBaseParam : function (name, value){
- this.baseParams = this.baseParams || {};
- this.baseParams[name] = value;
- }
-});
-
-Ext.reg('store', Ext.data.Store);
-
-/**
- * @class Ext.data.Store.Error
- * @extends Ext.Error
- * Store Error extension.
- * @param {String} name
- */
-Ext.data.Store.Error = Ext.extend(Ext.Error, {
- name: 'Ext.data.Store'
-});
-Ext.apply(Ext.data.Store.Error.prototype, {
- lang: {
- 'writer-undefined' : 'Attempted to execute a write-action without a DataWriter installed.'
+ // protected - should only be called by the grid. Use grid.getSource instead.
+ getSource : function() {
+ return this.source;
}
-});
-
-
-
-
\ No newline at end of file
+});
+
+