Observable Store
Package: | Ext.data |
Defined In: | Store.js |
Class: | Store |
Subclasses: | ArrayStore, DirectStore, GroupingStore, JsonStore, XmlStore |
Extends: | Observable |
The Store class encapsulates a client side cache of Record objects which provide input data for Components such as the GridPanel, the ComboBox, or the DataView.
Retrieving Data
A Store object may access a data object using:
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 configured implementation of a DataReader to create 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 Ext.data.Store configured as needed:
// create a 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:
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.insert(0, r); // insert a new record into the store (also see add)
Writing Data
And new in Ext version 3, use the new DataWriter to create an automated, Writable Store along with RESTful features.
Config Options | Defined By | |
---|---|---|
autoDestroy : Boolean true to destroy the store when the component the store is bound
to is destroyed (defaults to false).
Note: this shoul... true to destroy the store when the component the store is bound
to is destroyed (defaults to false).
Note: this should be set to true when using stores that are bound to only 1 component. | Store | |
autoLoad : Boolean/Object If data is not specified, and if autoLoad
is true or an Object, this store's load method is automatically called
afte... | Store | |
autoSave : Boolean Defaults to true causing the store to automatically save records to
the server when a record is modified (ie: becomes... | Store | |
baseParams : Object An object containing properties which are to be sent as parameters
for every HTTP request.
Parameters are encoded as ... An object containing properties which are to be sent as parameters for every HTTP request. Parameters are encoded as standard HTTP parameters using Ext.urlEncode. Note: setBaseParam
method. | Store | |
batch : Boolean Defaults to true (unless restful:true). Multiple
requests for each CRUD action (CREATE, READ, UPDATE and DESTROY) wil... Defaults to true (unless If Store is RESTful, the DataProxy is also RESTful, and a unique transaction is generated for each record. | Store | |
data : Array | Store | |
defaultParamNames : Object Provides the default values for the paramNames property. To globally modify the parameters
for all stores, this objec... Provides the default values for the paramNames property. To globally modify the parameters
for all stores, this object should be changed on the store prototype. | Store | |
listeners : Object A config object containing one or more event handlers to be added to this
object during initialization. This should ... A config object containing one or more event handlers to be added to this object during initialization. This should be a valid listeners config object as specified in the addListener example for attaching multiple handlers at once. DOM events from ExtJs Components While some ExtJs Component classes export selected DOM events (e.g. "click", "mouseover" etc), this
is usually only done when extra value can be added. For example the DataView's
| Observable | |
paramNames : Object An object containing properties which specify the names of the paging and
sorting parameters passed to remote servers... An object containing properties which specify the names of the paging and sorting parameters passed to remote servers when loading blocks of data. By default, this object takes the following form:
The server must produce the requested data block upon receipt of these parameter names. If different parameter names are required, this property can be overriden using a configuration property. A PagingToolbar bound to this Store uses this property to determine the parameter names to use in its requests. | Store | |
proxy : Ext.data.DataProxy | Store | |
pruneModifiedRecords : Boolean true to clear all modified record information each time
the store is loaded or when a record is removed (defaults to ... true to clear all modified record information each time
the store is loaded or when a record is removed (defaults to false). See getModifiedRecords
for the accessor method to retrieve the modified records. | Store | |
reader : Ext.data.DataReader The Reader object which processes the
data object and returns an Array of Ext.data.Record objects which are cached ke... The Reader object which processes the
data object and returns an Array of Ext.data.Record objects which are cached keyed by their
id property. | Store | |
remoteSort : boolean true if sorting is to be handled by requesting the Proxy
to provide a refreshed version of the data object in sorted ... true if sorting is to be handled by requesting the Proxy
to provide a refreshed version of the data object in sorted order, as opposed to sorting the Record cache
in place (defaults to false).
If remoteSort is true, then clicking on a Grid Column's header causes the current page to be requested from the server appending the following two parameters to the params:
| Store | |
restful : Boolean Defaults to false. Set to true to have the Store and the set
Proxy operate in a RESTful manner. The store will autom... Defaults to false. Set to true to have the Store and the set
Proxy operate in a RESTful manner. The store will automatically generate GET, POST,
PUT and DELETE requests to the server. The HTTP method used for any given CRUD
action is described in Ext.data.Api.restActions. For additional information
see Ext.data.DataProxy.restful.
Note: if | Store | |
sortInfo : Object A config object to specify the sort order in the request of a Store's
load operation. Note that for local sorting, t... A config object to specify the sort order in the request of a Store's
load operation. Note that for local sorting, the direction property is
case-sensitive. See also remoteSort and paramNames.
For example:
| Store | |
storeId : String | Store | |
url : String | Store | |
writer : Ext.data.DataWriter The Writer object which processes a record object for being written
to the server-side database.
When a writer is ins... The Writer object which processes a record object for being written to the server-side database. When a writer is installed into a Store the add, remove, and update events on the store are monitored in order to remotely create records, destroy records, or update records. The proxy for this store will relay any writexception events to this store. Sample implementation:
| Store |
Property | Defined By | |
---|---|---|
baseParams : Object See the corresponding configuration option
for a description of this property.
To modify this property see setBasePar... See the corresponding configuration option
for a description of this property.
To modify this property see setBaseParam . | Store | |
fields : Ext.util.MixedCollection | Store | |
hasMultiSort : Boolean True if this store is currently sorted by more than one field/direction combination. | Store | |
isDestroyed : Boolean True if the store has been destroyed already. Read only | Store | |
lastOptions : Object Contains the last options object used as the parameter to the load method. See load
for the details of what this may ... | Store | |
multiSortInfo : Object Object containing overall sort direction and an ordered array of sorter configs used when sorting on multiple fields | Store | |
recordType : Function The Record constructor as supplied to (or created by) the
Reader. Read-only.
If the Reader was constructed by passing... The Record constructor as supplied to (or created by) the
Reader. Read-only.
If the Reader was constructed by passing in an Array of Ext.data.Field definition objects, instead of a Record constructor, it will implicitly create a Record constructor from that Array (see Ext.data.Record.create for additional details). This property may be used to create new Records of the type held in this Store, for example:
| Store |
Method | Defined By | |
---|---|---|
Store( Object config )
Creates a new Store. Creates a new Store. Parameters:
| Store | |
add( Ext.data.Record[] records )
:
voidAdd Records to the Store and fires the add event. To add Records
to the store from a remote source use load({add:tru... Add Records to the Store and fires the add event. To add Records
to the store from a remote source use load({add:true}) .
See also recordType and insert .Parameters:
| Store | |
addEvents( Object|String o , string Optional. )
:
voidAdds the specified events to the list of events which this Observable may fire. Adds the specified events to the list of events which this Observable may fire. Parameters:
| Observable | |
addListener( String eventName , Function handler , [Object scope ], [Object options ] )
:
voidAppends an event handler to this object. Appends an event handler to this object. Parameters:
| Observable | |
addSorted( Ext.data.Record record )
:
void(Local sort only) Inserts the passed Record into the Store at the index where it
should go based on the current sort ... (Local sort only) Inserts the passed Record into the Store at the index where it
should go based on the current sort information. Parameters:
| Store | |
clearFilter( Boolean suppressEvent )
:
voidRevert to a view of the Record cache with no filtering applied. Revert to a view of the Record cache with no filtering applied. Parameters:
| Store | |
collect( String dataIndex , [Boolean allowNull ], [Boolean bypassFilter ] )
:
ArrayCollects unique values for a particular dataIndex from this store. Collects unique values for a particular dataIndex from this store. Parameters:
| Store | |
commitChanges()
:
void Commit all Records with outstanding changes. To handle updates for changes,
subscribe to the Store's update event, an... Commit all Records with outstanding changes. To handle updates for changes,
subscribe to the Store's update event, and perform updating when the third parameter is
Ext.data.Record.COMMIT. Parameters:
| Store | |
destroy()
:
void Destroys the store. Destroys the store. Parameters:
| Store | |
each( Function fn , [Object scope ] )
:
voidCalls the specified function for each of the Records in the cache. Calls the specified function for each of the Records in the cache. | Store | |
enableBubble( String/Array events )
:
voidEnables events fired by this Observable to bubble up an owner hierarchy by calling
this.getBubbleTarget() if present.... Enables events fired by this Observable to bubble up an owner hierarchy by calling
This is commonly used by Ext.Components to bubble events to owner Containers. See Ext.Component.getBubbleTarget. The default implementation in Ext.Component returns the Component's immediate owner. But if a known target is required, this can be overridden to access the required target more quickly. Example:
Parameters:
| Observable | |
filter( String|Array field , String/RegExp value , [Boolean anyMatch ], [Boolean caseSensitive ], Boolean exactMatch )
:
voidFilter the records by a specified property. Alternatively, pass an array of filter
options to filter by more than one... Filter the records by a specified property. Alternatively, pass an array of filter
options to filter by more than one property.
Single filter example:
store.filter('name', 'Ed', true, true); //finds all records containing the substring 'Ed'
Multiple filter example:
Parameters:
| Store | |
filterBy( Function fn , [Object scope ] )
:
voidFilter by a function. The specified function will be called for each
Record in this Store. If the function returns tr... 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. Parameters:
| Store | |
find( String fieldName , String/RegExp value , [Number startIndex ], [Boolean anyMatch ], [Boolean caseSensitive ] )
:
NumberFinds the index of the first matching Record in this store by a specific field value. Finds the index of the first matching Record in this store by a specific field value. Parameters:
| Store | |
findBy( Function fn , [Object scope ], [Number startIndex ] )
:
NumberFind the index of the first matching Record in this Store by a function.
If the function returns true it is considere... Find the index of the first matching Record in this Store by a function.
If the function returns true it is considered a match. Parameters:
| Store | |
findExact( String fieldName , Mixed value , [Number startIndex ] )
:
NumberFinds the index of the first matching Record in this store by a specific field value. Finds the index of the first matching Record in this store by a specific field value. Parameters:
| Store | |
fireEvent( String eventName , Object... args )
:
BooleanFires the specified event with the passed parameters (minus the event name).
An event may be set to bubble up an Obse... Fires the specified event with the passed parameters (minus the event name). An event may be set to bubble up an Observable parent hierarchy (See Ext.Component.getBubbleTarget) by calling enableBubble. Parameters:
| Observable | |
getAt( Number index )
:
Ext.data.RecordGet the Record at the specified index. Get the Record at the specified index. Parameters:
| Store | |
getById( String id )
:
Ext.data.RecordGet the Record with the specified id. Get the Record with the specified id. Parameters:
| Store | |
getCount()
:
Number Gets the number of cached records.
If using paging, this may not be the total size of the dataset. If the data object... Gets the number of cached records.
If using paging, this may not be the total size of the dataset. If the data object used by the Reader contains the dataset size, then the getTotalCount function returns the dataset size. Note: see the Important note in load. Parameters:
| Store | |
getModifiedRecords()
:
Ext.data.Record[] Gets all records modified since the last commit. Modified records are
persisted across load operations (e.g., during... Gets all 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 pruneModifiedRecords and
Ext.data.RecordmarkDirty.. Parameters:
| Store | |
getRange( [Number startIndex ], [Number endIndex ] )
:
Ext.data.Record[]Returns a range of Records between specified indices. Returns a range of Records between specified indices. Parameters:
| Store | |
getSortState()
:
Object Returns an object describing the current sort state of this Store. Returns an object describing the current sort state of this Store. Parameters:
| Store | |
getTotalCount()
:
Number Gets the total number of records in the dataset as returned by the server.
If using paging, for this to be accurate, ... Gets the total number of records in the dataset as returned by the server.
If using paging, for this to be accurate, the data object used by the Reader must contain the dataset size. For remote data sources, the value for this property (totalProperty for JsonReader, totalRecords for XmlReader) shall be returned by a query on the server. Note: see the Important note in load. Parameters:
| Store | |
hasListener( String eventName )
:
BooleanChecks to see if this object has any listeners for a specified event Checks to see if this object has any listeners for a specified event Parameters:
| Observable | |
indexOf( Ext.data.Record record )
:
NumberGet the index within the cache of the passed Record. Get the index within the cache of the passed Record. Parameters:
| Store | |
indexOfId( String id )
:
NumberGet the index within the cache of the Record with the passed id. Get the index within the cache of the Record with the passed id. Parameters:
| Store | |
insert( Number index , Ext.data.Record[] records )
:
voidInserts Records into the Store at the given index and fires the add event.
See also add and addSorted. | Store | |
isFiltered()
:
Boolean Returns true if this store is currently filtered Returns true if this store is currently filtered Parameters:
| Store | |
load( Object options )
:
BooleanLoads the Record cache from the configured proxy using the configured reader.
Notes:<div class="mdetail-params">
Impo... Loads the Record cache from the configured proxy using the configured reader. Notes:
Parameters:
| Store | |
loadData( Object data , [Boolean append ] )
:
voidLoads data from a passed data block and fires the load event. A Reader
which understands the format of the data must ... Loads data from a passed data block and fires the load event. A Reader
which understands the format of the data must have been configured in the constructor. Parameters:
| Store | |
multiSort( Array sorters , String direction )
:
voidSorts the contents of this store by multiple field/direction sorters. This is called internally by sort
and would not... Sorts the contents of this store by multiple field/direction sorters. This is called internally by sort
and would not usually be called manually.
Multi sorting only currently applies to local datasets - multiple sort data is not currently sent to a proxy
if remoteSort is used. Parameters:
| Store | |
on( String eventName , Function handler , [Object scope ], [Object options ] )
:
voidAppends an event handler to this object (shorthand for addListener.) Appends an event handler to this object (shorthand for addListener.) Parameters:
| Observable | |
purgeListeners()
:
void Removes all listeners for this object Removes all listeners for this object Parameters:
| Observable | |
query( String field , String/RegExp value , [Boolean anyMatch ], [Boolean caseSensitive ] )
:
MixedCollectionQuery the records by a specified property. Query the records by a specified property. Parameters:
| Store | |
queryBy( Function fn , [Object scope ] )
:
MixedCollectionQuery the cached records in this Store using a filtering function. The specified function
will be called with each re... Query the cached records in this Store using a filtering function. The specified function
will be called with each record in this Store. If the function returns true the record is
included in the results. Parameters:
| Store | |
rejectChanges()
:
void Reject outstanding changes on all modified records. | Store | |
relayEvents( Object o , Array events )
:
voidRelays selected events from the specified Observable as if the events were fired by this. Relays selected events from the specified Observable as if the events were fired by this. Parameters:
| Observable | |
reload( Object options )
:
voidReloads the Record cache from the configured Proxy using the configured
Reader and the options from the last load ope... Reloads the Record cache from the configured Proxy using the configured Reader and the options from the last load operation performed. Note: see the Important note in load. Parameters:
| Store | |
remove( Ext.data.Record/Ext.data.Record[] record )
:
voidRemove Records from the Store and fires the remove event. Remove Records from the Store and fires the remove event. Parameters:
| Store | |
removeAll( Boolean silent )
:
voidRemove all Records from the Store and fires the clear event. Remove all Records from the Store and fires the clear event. Parameters:
| Store | |
removeAt( Number index )
:
voidRemove a Record from the Store at the specified index. Fires the remove event. Remove a Record from the Store at the specified index. Fires the remove event. Parameters:
| Store | |
removeListener( String eventName , Function handler , [Object scope ] )
:
voidRemoves an event handler. Removes an event handler. Parameters:
| Observable | |
resumeEvents()
:
void Resume firing events. (see suspendEvents)
If events were suspended using the queueSuspended parameter, then all
event... Resume firing events. (see suspendEvents)
If events were suspended using the queueSuspended parameter, then all
events fired during event suspension will be sent to any listeners now. Parameters:
| Observable | |
save()
:
Number Saves all pending changes to the store. If the commensurate Ext.data.Api.actions action is not configured, then
the ... Saves all pending changes to the store. If the commensurate Ext.data.Api.actions action is not configured, then
the configured url will be used.
change url --------------- -------------------- removed records Ext.data.Api.actions.destroy phantom records Ext.data.Api.actions.create modified records Ext.data.Api.actions.update Parameters:
| Store | |
setBaseParam( String name , Mixed value )
:
voidSet the value for a property name in this store's baseParams. Usage:myStore.setBaseParam('foo', {bar:3}); Set the value for a property name in this store's baseParams. Usage:
Parameters:
| Store | |
setDefaultSort( String fieldName , [String dir ] )
:
voidSets the default sort column and order to be used by the next load operation. Sets the default sort column and order to be used by the next load operation. Parameters:
| Store | |
singleSort( String fieldName , [String dir ] )
:
voidSorts the store contents by a single field and direction. This is called internally by sort and would
not usually be ... Sorts the store contents by a single field and direction. This is called internally by sort and would
not usually be called manually Parameters:
| Store | |
sort( String/Array fieldName , [String dir ] )
:
voidSort the Records.
If remote sorting is used, the sort is performed on the server, and the cache is reloaded. If local... Sort the Records.
If remote sorting is used, the sort is performed on the server, and the cache is reloaded. If local
sorting is used, the cache is sorted internally. See also remoteSort and paramNames.
This function accepts two call signatures - pass in a field name as the first argument to sort on a single
field, or pass in an array of sort configuration objects to sort by multiple fields.
Single sort example:
store.sort('name', 'ASC');
Multi sort example:
store.sort([
{
field : 'name',
direction: 'ASC'
},
{
field : 'salary',
direction: 'DESC'
}
], 'ASC');
In this second form, the sort configs are applied in order, with later sorters sorting within earlier sorters' results.
For example, if two records with the same name are present they will also be sorted by salary if given the sort configs
above. Any number of sort configs can be added. Parameters:
| Store | |
sum( String property , [Number start ], [Number end ] )
:
NumberSums the value of property for each record between start
and end and returns the result. Sums the value of property for each record between start
and end and returns the result. Parameters:
| Store | |
suspendEvents( Boolean queueSuspended )
:
voidSuspend the firing of all events. (see resumeEvents) Suspend the firing of all events. (see resumeEvents) Parameters:
| Observable | |
un( String eventName , Function handler , [Object scope ] )
:
voidRemoves an event handler (shorthand for removeListener.) Removes an event handler (shorthand for removeListener.) Parameters:
| Observable |
Event | Defined By | |
---|---|---|
add :
( Store this , Ext.data.Record[] records , Number index )
Fires when Records have been added to the Store Fires when Records have been added to the Store Listeners will be called with the following arguments:
| Store | |
beforeload :
( Store this , Object options )
Fires before a request is made for a new data object. If the beforeload handler returns
false the load action will b... | Store | |
beforesave :
( Ext.data.Store store , Object data )
Fires before a save action is called. A save encompasses destroying records, updating records and creating records. Fires before a save action is called. A save encompasses destroying records, updating records and creating records. Listeners will be called with the following arguments:
| Store | |
beforewrite :
( Ext.data.Store store , String action , Record/Record[] rs , Object options , Object arg )
Listeners will be called with the following arguments:
| Store | |
clear :
( Store this , Record[] The )
Fires when the data cache has been cleared. Fires when the data cache has been cleared. Listeners will be called with the following arguments:
| Store | |
datachanged :
( Store this )
Fires when the data cache has changed in a bulk manner (e.g., it has been sorted, filtered, etc.) and a
widget that i... 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. Listeners will be called with the following arguments:
| Store | |
exception :
( misc misc )
Fires if an exception occurs in the Proxy during a remote request.
This event is relayed through the corresponding Ex... Fires if an exception occurs in the Proxy during a remote request. This event is relayed through the corresponding Ext.data.DataProxy. See Ext.data.DataProxy.exception for additional details. Listeners will be called with the following arguments:
| Store | |
load :
( Store this , Ext.data.Record[] records , Object options )
Fires after a new set of Records has been loaded. Fires after a new set of Records has been loaded. Listeners will be called with the following arguments:
| Store | |
loadexception :
( misc misc )
This event is deprecated in favor of the catch-all exception
event instead.
This event is relayed through the corresp... This event is deprecated in favor of the catch-all This event is relayed through the corresponding Ext.data.DataProxy. See Ext.data.DataProxy.loadexception for additional details. Listeners will be called with the following arguments:
| Store | |
metachange :
( Store this , Object meta )
Fires when this store's reader provides new metadata (fields). This is currently only supported for JsonReaders. Fires when this store's reader provides new metadata (fields). This is currently only supported for JsonReaders. Listeners will be called with the following arguments:
| Store | |
remove :
( Store this , Ext.data.Record record , Number index )
Fires when a Record has been removed from the Store Fires when a Record has been removed from the Store Listeners will be called with the following arguments:
| Store | |
save :
( Ext.data.Store store , Number batch , Object data )
Fires after a save is completed. A save encompasses destroying records, updating records and creating records. Fires after a save is completed. A save encompasses destroying records, updating records and creating records. Listeners will be called with the following arguments:
| Store | |
update :
( Store this , Ext.data.Record record , String operation )
Fires when a Record has been updated Fires when a Record has been updated Listeners will be called with the following arguments:
| Store | |
write :
( Ext.data.Store store , String action , Object result , Ext.Direct.Transaction res , Record/Record[] rs )
Fires if the server returns 200 after an Ext.data.Api.actions CRUD action.
Success of the action is determined in the... Fires if the server returns 200 after an Ext.data.Api.actions CRUD action.
Success of the action is determined in the result['successProperty'] property (NOTE for RESTful stores,
a simple 20x response is sufficient for the actions "destroy" and "update". The "create" action should should return 200 along with a database pk).Listeners will be called with the following arguments:
| Store |