Hierarchy
Ext.BaseExt.EventedExt.data.StoreInherited mixins
Requires
Subclasses
Files
The Store class encapsulates a client side cache of Model objects. Stores load data via a Proxy, and also provide functions for sorting, filtering and querying the model instances contained within it.
Creating a Store is easy - we just tell it the Model and the Proxy to use to load and save its data:
// Set up a model to use in our Store
Ext.define("User", {
extend: "Ext.data.Model",
config: {
fields: [
{name: "firstName", type: "string"},
{name: "lastName", type: "string"},
{name: "age", type: "int"},
{name: "eyeColor", type: "string"}
]
}
});
var myStore = Ext.create("Ext.data.Store", {
model: "User",
proxy: {
type: "ajax",
url : "/users.json",
reader: {
type: "json",
rootProperty: "users"
}
},
autoLoad: true
});
Ext.create("Ext.List", {
fullscreen: true,
store: myStore,
itemTpl: "{lastName}, {firstName} ({age})"
});
In the example above we configured an AJAX proxy to load data from the url '/users.json'. We told our Proxy to use a JsonReader to parse the response from the server into Model object - see the docs on JsonReader for details.
The external data file, /users.json, is as follows:
{
"success": true,
"users": [
{
"firstName": "Tommy",
"lastName": "Maintz",
"age": 24,
"eyeColor": "green"
},
{
"firstName": "Aaron",
"lastName": "Conran",
"age": 26,
"eyeColor": "blue"
},
{
"firstName": "Jamie",
"lastName": "Avins",
"age": 37,
"eyeColor": "brown"
}
]
}
Stores can also load data inline. Internally, Store converts each of the objects we pass in as data into Model instances:
// Set up a model to use in our Store
Ext.define('User', {
extend: 'Ext.data.Model',
config: {
fields: [
{name: 'firstName', type: 'string'},
{name: 'lastName', type: 'string'},
{name: 'age', type: 'int'},
{name: 'eyeColor', type: 'string'}
]
}
});
Ext.create("Ext.data.Store", {
storeId: "usersStore",
model: "User",
data : [
{firstName: "Ed", lastName: "Spencer"},
{firstName: "Tommy", lastName: "Maintz"},
{firstName: "Aaron", lastName: "Conran"},
{firstName: "Jamie", lastName: "Avins"}
]
});
Ext.create("Ext.List", {
fullscreen: true,
store: "usersStore",
itemTpl: "{lastName}, {firstName}"
});
Loading inline data using the method above is great if the data is in the correct format already (e.g. it doesn't need to be processed by a reader). If your inline data requires processing to decode the data structure, use a MemoryProxy instead (see the MemoryProxy docs for an example).
Additional data can also be loaded locally using add.
Applications often need to load sets of associated data - for example a CRM system might load a User and her Orders. Instead of issuing an AJAX request for the User and a series of additional AJAX requests for each Order, we can load a nested dataset and allow the Reader to automatically populate the associated models. Below is a brief example, see the Ext.data.reader.Reader intro documentation for a full explanation:
// Set up a model to use in our Store
Ext.define('User', {
extend: 'Ext.data.Model',
config: {
fields: [
{name: 'name', type: 'string'},
{name: 'id', type: 'int'}
]
}
});
var store = Ext.create('Ext.data.Store', {
autoLoad: true,
model: "User",
proxy: {
type: 'ajax',
url : 'users.json',
reader: {
type: 'json',
rootProperty: 'users'
}
}
});
Ext.create("Ext.List", {
fullscreen: true,
store: store,
itemTpl: "{name} (id: {id})"
});
Which would consume a response like this:
{
"users": [
{
"id": 1,
"name": "Ed",
"orders": [
{
"id": 10,
"total": 10.76,
"status": "invoiced"
},
{
"id": 11,
"total": 13.45,
"status": "shipped"
}
]
},
{
"id": 3,
"name": "Tommy",
"orders": [
]
},
{
"id": 4,
"name": "Jamie",
"orders": [
{
"id": 12,
"total": 17.76,
"status": "shipped"
}
]
}
]
}
See the Ext.data.reader.Reader intro docs for a full explanation.
Stores can be sorted and filtered - in both cases either remotely or locally. The sorters and filters are held inside MixedCollection instances to make them easy to manage. Usually it is sufficient to either just specify sorters and filters in the Store configuration or call sort or filter:
// Set up a model to use in our Store
Ext.define('User', {
extend: 'Ext.data.Model',
config: {
fields: [
{name: 'firstName', type: 'string'},
{name: 'lastName', type: 'string'},
{name: 'age', type: 'int'}
]
}
});
var store = Ext.create("Ext.data.Store", {
autoLoad: true,
model: "User",
proxy: {
type: "ajax",
url : "users.json",
reader: {
type: "json",
rootProperty: "users"
}
},
sorters: [
{
property : "age",
direction: "DESC"
},
{
property : "firstName",
direction: "ASC"
}
],
filters: [
{
property: "firstName",
value: /Jamie/
}
]
});
Ext.create("Ext.List", {
fullscreen: true,
store: store,
itemTpl: "{lastName}, {firstName} ({age})"
});
And the data file, users.json, is as follows:
{
"success": true,
"users": [
{
"firstName": "Tommy",
"lastName": "Maintz",
"age": 24
},
{
"firstName": "Aaron",
"lastName": "Conran",
"age": 26
},
{
"firstName": "Jamie",
"lastName": "Avins",
"age": 37
}
]
}
The new Store will keep the configured sorters and filters in the MixedCollection instances mentioned above. By default, sorting and filtering are both performed locally by the Store - see remoteSort and remoteFilter to allow the server to perform these operations instead.
Filtering and sorting after the Store has been instantiated is also easy. Calling filter adds another filter to the Store and automatically filters the dataset (calling filter with no arguments simply re-applies all existing filters). Note that by default your sorters are automatically reapplied if using local sorting.
store.filter('eyeColor', 'Brown');
Change the sorting at any time by calling sort:
store.sort('height', 'ASC');
Note that all existing sorters will be removed in favor of the new sorter data (if sort is called with no arguments, the existing sorters are just reapplied instead of being removed). To keep existing sorters and add new ones, just add them to the MixedCollection:
store.sorters.add(new Ext.util.Sorter({
property : 'shoeSize',
direction: 'ASC'
}));
store.sort();
Any Store that is instantiated with a storeId will automatically be registered with the StoreManager. This makes it easy to reuse the same store in multiple views:
// this store can be used several times
Ext.create('Ext.data.Store', {
model: 'User',
storeId: 'usersStore'
});
Ext.create('Ext.List', {
store: 'usersStore'
// other config goes here
});
Ext.create('Ext.view.View', {
store: 'usersStore'
// other config goes here
});
Stores are backed up by an ecosystem of classes that enables their operation. To gain a full understanding of these pieces and how they fit together, see:
This is a private configuration used in the framework whether this Store can be destroyed.
Defaults to: false
If data is not specified, and if autoLoad
is true
or an Object, this store's load method is automatically called
after creation. If the value of autoLoad
is an Object, this Object will be passed to the store's load()
method.
Defaults to: false
true
to automatically sync the Store with its Proxy after every edit to one of its Records.
Defaults to: false
The event name to bubble, or an Array of event names.
The event name to bubble, or an Array of event names.
Allows the Store to prefetch and cache in a page cache, pages of Records, and to then satisfy loading requirements from this page cache.
To use buffered Stores, initiate the process by loading the first page. The number of rows rendered are determined automatically, and the range of pages needed to keep the cache primed for scrolling is requested and cached. Example:
myStore.loadPage(1); // Load page 1
A BufferedRenderer is instantiated which will monitor the scrolling in the grid, and refresh the view's rows from the page cache as needed. It will also pull new data into the page cache when scrolling of the view draws upon data near either end of the prefetched data.
The margins which trigger view refreshing from the prefetched data are Ext.grid.plugin.BufferedRenderer.numFromEdge, Ext.grid.plugin.BufferedRenderer.leadingBufferZone and Ext.grid.plugin.BufferedRenderer.trailingBufferZone.
The margins which trigger loading more data into the page cache are, leadingBufferZone and trailingBufferZone.
By default, only 5 pages of data are cached in the page cache, with pages "scrolling" out of the buffer as the view moves down through the dataset. Setting this value to zero means that no pages are ever scrolled out of the page cache, and that eventually the whole dataset may become present in the page cache. This is sometimes desirable as long as datasets do not reach astronomical proportions.
Selection state may be maintained across page boundaries by configuring the SelectionModel not to discard records from its collection when those Records cycle out of the Store's primary collection. This is done by configuring the SelectionModel like this:
selModel: {
pruneRemoved: false
}
Defaults to: false
true
to empty the store when loading another page via loadPage,
nextPage or previousPage. Setting to false
keeps existing records, allowing
large data sets to be loaded one page at a time but rendered all together.
Defaults to: true
Array of Model instances or data objects to load locally. See "Inline data" above for details.
This configuration allows you to prevent destroying record instances when they are removed from this store and are not in any other store.
Defaults to: true
Returns Ext.util.Collection not just an Object. Use in place of specifying a model configuration. The fields should be a set of Ext.data.Field configuration objects. The store will automatically create a Ext.data.Model with these fields. In general this configuration option should be avoided, it exists for the purposes of backwards compatibility. For anything more complicated, such as specifying a particular id property or associations, a Ext.data.Model should be defined and specified for the model config.
Array of Filters for this store. This configuration is handled by the Filterable mixin of the data collection.
This function will be passed to the grouper configuration as it's groupFn
.
Note that this configuration is deprecated and grouper: {groupFn: yourFunction}}
is preferred.
This cfg has been deprecated
The direction in which sorting should be applied when grouping. If you specify a grouper by using the groupField configuration, this will automatically default to "ASC" - the other supported value is "DESC"
A configuration object for this Store's grouper.
For example, to group a store's items by the first letter of the last name:
Ext.define('People', {
extend: 'Ext.data.Store',
config: {
fields: ['first_name', 'last_name'],
grouper: {
groupFn: function(record) {
return record.get('last_name').substr(0, 1);
},
sortProperty: 'last_name'
}
}
});
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.
See the Event guide for more
Note: It is bad practice to specify a listener's config
when you are defining a class using Ext.define()
.
Instead, only specify listeners when you are instantiating your class with Ext.create()
.
Returns Ext.data.Model and not a String. Name of the Model associated with this store. The string is used as an argument for Ext.ModelManager.getModel.
The number of records considered to form a 'page'. This is used to power the built-in paging using the nextPage and previousPage functions.
If this Store is buffered, pages are loaded into a page cache before the Store's data is updated from the cache. The pageSize is the number of rows loaded into the cache in one request. This will not affect the rendering of a buffered grid, but a larger page size will mean fewer loads.
In a buffered grid, scrolling is monitored, and the page cache is kept primed with data ahead of the direction of scroll to provide rapid access to data when scrolling causes it to be required. Several pages in advance may be requested depending on various parameters.
It is recommended to tune the pageSize, trailingBufferZone and leadingBufferZone configurations based upon the conditions pertaining in your deployed application.
Defaults to: 25
Parameters to send into the proxy for any CRUD operations
Defaults to: {}
An object or array of objects that will provide custom functionality for this component. The only requirement for a valid plugin is that it contain an init method that accepts a reference of type Ext.Component.
When a component is created, if any plugins are available, the component will call the init method on each plugin, passing a reference to itself. Each plugin can then call methods or respond to events on the component as needed to provide its functionality.
For examples of plugins, see Ext.plugin.PullRefresh and Ext.plugin.ListPaging
A plugin by alias:
Ext.create('Ext.dataview.List', {
config: {
plugins: 'listpaging',
itemTpl: '<div class="item">{title}</div>',
store: 'Items'
}
});
Multiple plugins by alias:
Ext.create('Ext.dataview.List', {
config: {
plugins: ['listpaging', 'pullrefresh'],
itemTpl: '<div class="item">{title}</div>',
store: 'Items'
}
});
Single plugin by class name with config options:
Ext.create('Ext.dataview.List', {
config: {
plugins: {
xclass: 'Ext.plugin.ListPaging', // Reference plugin by class
autoPaging: true
},
itemTpl: '<div class="item">{title}</div>',
store: 'Items'
}
});
Multiple plugins by class name with config options:
Ext.create('Ext.dataview.List', {
config: {
plugins: [
{
xclass: 'Ext.plugin.PullRefresh',
pullRefreshText: 'Pull to refresh...'
},
{
xclass: 'Ext.plugin.ListPaging',
autoPaging: true
}
],
itemTpl: '<div class="item">{title}</div>',
store: 'Items'
}
});
The Proxy to use for this Store. This can be either a string, a config object or a Proxy instance - see setProxy for details.
true
to defer any filtering operation to the server. If false
, filtering is done locally on the client.
If this is set to true
, you will have to manually call the load method after you filter to retrieve the filtered
data from the server.
Buffered stores automatically set this to true
. Buffered stores contain an abitrary
subset of the full dataset which depends upon various configurations and which pages have been requested
for rendering. Such sparse datasets are ineligible for local filtering.
Defaults to: false
true
to defer any grouping operation to the server. If false
, grouping is done locally on the client.
Buffered stores automatically set this to true
. Buffered stores contain an abitrary
subset of the full dataset which depends upon various configurations and which pages have been requested
for rendering. Such sparse datasets are ineligible for local grouping.
Defaults to: false
true
to defer any sorting operation to the server. If false
, sorting is done locally on the client.
If this is set to true
, you will have to manually call the load method after you sort, to retrieve the sorted
data from the server.
Buffered stores automatically set this to true
. Buffered stores contain an abitrary
subset of the full dataset which depends upon various configurations and which pages have been requested
for rendering. Such sparse datasets are ineligible for local sorting.
Defaults to: false
Unique identifier for this store. If present, this Store will be registered with the Ext.data.StoreManager, making it easy to reuse elsewhere.
This configuration allows you to disable the synchronization of
removed records on this Store. By default, when you call removeAll()
or remove()
, records will be added
to an internal removed array. When you then sync the Store, we send a destroy request for these records.
If you don't want this to happen, you can set this configuration to false
.
Defaults to: true
The total number of records in the full dataset, as indicated by a server. If the
server-side dataset contains 5000 records but only returns pages of 50 at a time, totalCount
will be set to
5000 and getCount will return 50
The page that the Store has most recently loaded (see loadPage)
Defaults to: 1
Defaults to: {id: 'observable', hooks: {destroy: 'destroy'}}
Overrides: Ext.mixin.Sortable.mixinConfig
Get the reference to the current class from which this object was instantiated. Unlike statics,
this.self
is scope-dependent and it's meant to be used for dynamic inheritance. See statics
for a detailed comparison
Ext.define('My.Cat', {
statics: {
speciesName: 'Cat' // My.Cat.speciesName = 'Cat'
},
constructor: function() {
alert(this.self.speciesName); // dependent on 'this'
},
clone: function() {
return new this.self();
}
});
Ext.define('My.SnowLeopard', {
extend: 'My.Cat',
statics: {
speciesName: 'Snow Leopard' // My.SnowLeopard.speciesName = 'Snow Leopard'
}
});
var cat = new My.Cat(); // alerts 'Cat'
var snowLeopard = new My.SnowLeopard(); // alerts 'Snow Leopard'
var clone = snowLeopard.clone();
alert(Ext.getClassName(clone)); // alerts 'My.SnowLeopard'
Adds Model instance to the Store. This method accepts either:
The new Model instances will be added at the end of the existing collection.
Sample usage:
myStore.add({some: 'data2'}, {some: 'other data2'});
Use addData method instead if you have raw data that need to pass through the data reader.
An array of Model instances or Model configuration objects, or variable number of Model instance or config arguments.
The model instances that were added.
Appends an after-event handler.
Same as addListener with order
set to 'after'
.
The name of the event to listen for.
The method the event invokes.
The scope for fn
.
An object containing handler configuration.
Appends a before-event handler. Returning false
from the handler will stop the event.
Same as addListener with order
set to 'before'
.
The name of the event to listen for.
The method the event invokes.
The scope for fn
.
An object containing handler configuration.
Uses the configured reader to convert the data into records and adds it to the Store. Use this when you have raw data that needs to pass trough converters, mappings and other extra logic from the reader.
If your data is already formated and ready for consumption, use add method.
Array of data to load
Adds the specified events to the list of events which this Observable may fire.
This method has been deprecated since 2.0
It's no longer needed to add events before firing.
Appends an event handler to this object. You can review the available handlers by looking at the 'events' section of the documentation for the component you are working with.
Using the options argument, it is possible to combine different types of listeners:
A delayed, one-time listener:
container.addListener('tap', this.handleTap, this, {
single: true,
delay: 100
});
The method also allows for a single argument to be passed which is a config object containing properties which specify multiple events. For example:
container.addListener({
tap : this.onTap,
swipe: this.onSwipe,
scope: this // Important. Ensure "this" is correct during handler execution
});
One can also specify options for each event handler separately:
container.addListener({
tap : { fn: this.onTap, scope: this, single: true },
swipe: { fn: button.onSwipe, scope: button }
});
See the Events Guide for more.
The name of the event to listen for. May also be an object who's property names are event names.
The method the event invokes. Will be called with arguments given to
fireEvent plus the options
parameter described below.
The scope (this
reference) in which the handler function is executed. If
omitted, defaults to the object which fired the event.
An object containing handler configuration.
This object may contain any of the following properties:
The scope (this
reference) in which the handler function is executed. If omitted, defaults to the object
which fired the event.
The number of milliseconds to delay the invocation of the handler after the event fires.
true
to add a handler to handle just the next firing of the event, and then remove itself.
The order of when the listener should be added into the listener queue.
If you set an order of before
and the event you are listening to is preventable, you can return false
and it will stop the event.
Available options are before
, current
and after
.
Defaults to: current
Causes the handler to be delayed by the specified number of milliseconds. If the event fires again within that time, the original handler is not invoked, but the new handler is scheduled in its place.
Allows you to add a listener onto a element of this component using the elements reference.
Ext.create('Ext.Component', {
listeners: {
element: 'element',
tap: function() {
alert('element tap!');
}
}
});
All components have the element
reference, which is the outer most element of the component. Ext.Container also has the
innerElement
element which contains all children. In most cases element
is adequate.
Uses Ext.ComponentQuery to delegate events to a specified query selector within this item.
// Create a container with a two children; a button and a toolbar
var container = Ext.create('Ext.Container', {
items: [
{
xtype: 'toolbar',
docked: 'top',
title: 'My Toolbar'
},
{
xtype: 'button',
text: 'My Button'
}
]
});
container.addListener({
// Ext.Buttons have an xtype of 'button', so we use that are a selector for our delegate
delegate: 'button',
tap: function() {
alert('Button tapped!');
}
});
The order of when the listener should be added into the listener queue.
Possible values are before
, current
and after
.
Defaults to: 'current'
Adds listeners to any Observable object (or Element) which are automatically removed when this Component is destroyed.
This method has been deprecated since 2.0
All listeners are now automatically managed where necessary. Simply use addListener.
The item to which to add a listener/listeners.
The event name, or an object containing event name properties.
If the eventName
parameter was an event name, this is the handler function.
If the eventName
parameter was an event name, this is the scope in which
the handler function is executed.
If the eventName
parameter was an event name, this is the
addListener options.
A model instance should call this method on the Store it has been joined to.
The model instance that was edited.
A model instance should call this method on the Store it has been joined to.
The model instance that was edited.
Array of field names changed during edit.
This gets called by a record after is gets erased from the server.
A model instance should call this method on the Store it has been joined to.
The model instance that was edited.
We are using applyData so that we can return nothing and prevent the this.data
property to be overridden.
Call the original method that was previously overridden with override,
This method is deprecated as callParent does the same thing.
Ext.define('My.Cat', {
constructor: function() {
alert("I'm a cat!");
}
});
My.Cat.override({
constructor: function() {
alert("I'm going to be a cat!");
var instance = this.callOverridden();
alert("Meeeeoooowwww");
return instance;
}
});
var kitty = new My.Cat(); // alerts "I'm going to be a cat!"
// alerts "I'm a cat!"
// alerts "Meeeeoooowwww"
The arguments, either an array or the arguments
object
from the current method, for example: this.callOverridden(arguments)
Returns the result of calling the overridden method
Call the "parent" method of the current method. That is the method previously overridden by derivation or by an override (see Ext.define).
Ext.define('My.Base', {
constructor: function (x) {
this.x = x;
},
statics: {
method: function (x) {
return x;
}
}
});
Ext.define('My.Derived', {
extend: 'My.Base',
constructor: function () {
this.callParent([21]);
}
});
var obj = new My.Derived();
alert(obj.x); // alerts 21
This can be used with an override as follows:
Ext.define('My.DerivedOverride', {
override: 'My.Derived',
constructor: function (x) {
this.callParent([x*2]); // calls original My.Derived constructor
}
});
var obj = new My.Derived();
alert(obj.x); // now alerts 42
This also works with static methods.
Ext.define('My.Derived2', {
extend: 'My.Base',
statics: {
method: function (x) {
return this.callParent([x*2]); // calls My.Base.method
}
}
});
alert(My.Base.method(10)); // alerts 10
alert(My.Derived2.method(10)); // alerts 20
Lastly, it also works with overridden static methods.
Ext.define('My.Derived2Override', {
override: 'My.Derived2',
statics: {
method: function (x) {
return this.callParent([x*2]); // calls My.Derived2.method
}
}
});
alert(My.Derived2.method(10)); // now alerts 40
To override a method and replace it and also call the superclass method, use callSuper. This is often done to patch a method to fix a bug.
The arguments, either an array or the arguments
object
from the current method, for example: this.callParent(arguments)
Returns the result of calling the parent method
This method is used by an override to call the superclass method but bypass any overridden method. This is often done to "patch" a method that contains a bug but for whatever reason cannot be fixed directly.
Consider:
Ext.define('Ext.some.Class', {
method: function () {
console.log('Good');
}
});
Ext.define('Ext.some.DerivedClass', {
method: function () {
console.log('Bad');
// ... logic but with a bug ...
this.callParent();
}
});
To patch the bug in DerivedClass.method
, the typical solution is to create an
override:
Ext.define('App.paches.DerivedClass', {
override: 'Ext.some.DerivedClass',
method: function () {
console.log('Fixed');
// ... logic but with bug fixed ...
this.callSuper();
}
});
The patch method cannot use callParent
to call the superclass method
since
that would call the overridden method containing the bug. In other words, the
above patch would only produce "Fixed" then "Good" in the console log, whereas,
using callParent
would produce "Fixed" then "Bad" then "Good".
The arguments, either an array or the arguments
object
from the current method, for example: this.callSuper(arguments)
Returns the result of calling the superclass method
Calls the specified function for each of the Records in the cache.
// Set up a model to use in our Store
Ext.define('User', {
extend: 'Ext.data.Model',
config: {
fields: [
{name: 'firstName', type: 'string'},
{name: 'lastName', type: 'string'}
]
}
});
var store = Ext.create('Ext.data.Store', {
model: 'User',
data : [
{firstName: 'Ed', lastName: 'Spencer'},
{firstName: 'Tommy', lastName: 'Maintz'},
{firstName: 'Aaron', lastName: 'Conran'},
{firstName: 'Jamie', lastName: 'Avins'}
]
});
store.each(function (item, index, length) {
console.log(item.get('firstName'), index);
});
Filters the loaded set of records by a given set of filters.
Filtering by single field:
store.filter("email", /\.com$/);
Using multiple filters:
store.filter([
{property: "email", value: /\.com$/},
{filterFn: function(item) { return item.get("age") > 10; }}
]);
Using Ext.util.Filter instances instead of config objects (note that we need to specify the root config option in this case):
store.filter([
Ext.create('Ext.util.Filter', {property: "email", value: /\.com$/, root: 'data'}),
Ext.create('Ext.util.Filter', {filterFn: function(item) { return item.get("age") > 10; }, root: 'data'})
]);
If the remoteFilter configuration has been set to true
, you will have to manually call the load
method after you filter to retrieve the filtered data from the server.
The set of filters to apply to the data. These are stored internally on the store, but the filtering itself is done on the Store's MixedCollection. See MixedCollection's filter method for filter syntax. Alternatively, pass in a property string.
value to filter by (only if using a property string as the first argument).
true
to allow any match, false to anchor regex beginning with ^
.
Defaults to: false
true
to make the filtering regex case sensitive.
Defaults to: false
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.
The function to be called. It will be passed the following parameters:
The record to test for filtering. Access field values using Ext.data.Model.get.
The ID of the Record passed.
The scope (this
reference) in which the function is executed. Defaults to this Store.
Finds the index of the first matching Record in this store by a specific field value.
The name of the Record field to test.
Either a string that the field value should begin with, or a RegExp to test against the field.
The index to start searching at.
true
to match any part of the string, not just the beginning.
true
for case sensitive comparison.
true
to force exact match (^ and $ characters added to the regex).
Defaults to: false
The matched index or -1
Find the index of the first matching Record in this Store by a function.
If the function returns true
it is considered a match.
The function to be called. It will be passed the following parameters:
The record to test for filtering. Access field values using Ext.data.Model.get.
The ID of the Record passed.
The scope (this
reference) in which the function is executed. Defaults to this Store.
The index to start searching at.
The matched index or -1.
Finds the index of the first matching Record in this store by a specific field value.
The name of the Record field to test.
The value to match the field against.
The index to start searching at.
The matched index or -1.
Finds the first matching Record in this store by a specific field value.
The name of the Record field to test.
Either a string that the field value should begin with, or a RegExp to test against the field.
The index to start searching at.
true
to match any part of the string, not just the beginning.
true
for case sensitive comparison.
true
to force exact match (^ and $ characters added to the regex).
Defaults to: false
The matched record or null
.
Fires the specified event with the passed parameters and execute a function (action)
at the end if there are no listeners that return false
.
The name of the event to fire.
Arguments to pass to handers.
Action.
Scope of fn.
Fires the specified event with the passed parameters (minus the event name, plus the options
object passed
to addListener).
The first argument is the name of the event. Every other argument passed will be available when you listen for the event.
Firstly, we set up a listener for our new event.
this.on('myevent', function(arg1, arg2, arg3, arg4, options, e) {
console.log(arg1); // true
console.log(arg2); // 2
console.log(arg3); // { test: 'foo' }
console.log(arg4); // 14
console.log(options); // the options added when adding the listener
console.log(e); // the event object with information about the event
});
And then we can fire off the event.
this.fireEvent('myevent', true, 2, { test: 'foo' }, 14);
An event may be set to bubble up an Observable parent hierarchy by calling enableBubble.
The name of the event to fire.
Variable number of parameters are passed to handlers.
Returns false
if any of the handlers return false
.
Convenience function for getting the first model instance in the store.
The first model instance in the store, or undefined
.
Gets the number of all cached records including the ones currently filtered. If using paging, this may not be the total size of the dataset.
The number of all Records in the Store's cache.
Get the Record at the specified index.
The index of the Record to find.
The Record at the passed index. Returns undefined
if not found.
Get the Record with the specified id.
The id of the Record to find.
The Record with the passed id. Returns undefined
if not found.
Gets the number of cached records. Note that filtered records are not included in this count. If using paging, this may not be the total size of the dataset.
The number of Records in the Store's cache.
Returns an array containing the result of applying the grouper to the records in this store. See groupField, groupDir and grouper. Example for a store containing records with a color field:
var myStore = Ext.create('Ext.data.Store', {
groupField: 'color',
groupDir : 'DESC'
});
myStore.getGroups(); //returns:
[
{
name: 'yellow',
children: [
//all records where the color field is 'yellow'
]
},
{
name: 'red',
children: [
//all records where the color field is 'red'
]
}
]
Pass in an optional groupName
argument to access a specific group as defined by grouper.
Retrieves the id of this component. Will autogenerate an id if one has not already been set.
id
Returns all Model instances that are either currently a phantom (e.g. have no id), or have an ID but have not yet been saved on this Store (this happens when adding a non-phantom record from another Store into this one).
The Model instances.
Returns a range of Records between specified indices. Note that if the store is filtered, only filtered results are returned.
The starting index.
Defaults to: 0
The ending index (defaults to the last Record in the Store).
Defaults to: -1
An array of Records.
Returns any records that have been removed from the store but not yet destroyed on the proxy.
The removed Model instances.
Returns all Model instances that have been updated in the Store but not yet synchronized with the Proxy.
The updated Model instances.
Get the index within the cache of the passed Record.
The Ext.data.Model object to find.
The index of the passed Record. Returns -1 if not found.
Initialize configuration for this class. a typical example:
Ext.define('My.awesome.Class', {
// The default config
config: {
name: 'Awesome',
isAwesome: true
},
constructor: function(config) {
this.initConfig(config);
}
});
var awesome = new My.awesome.Class({
name: 'Super Awesome'
});
alert(awesome.getName()); // 'Super Awesome'
mixins The mixin prototypes as key - value pairs
Inserts Model instances into the Store at the given index and fires the add event.
See also add
.
The start index at which to insert the passed Records.
An Array of Ext.data.Model objects to add to the cache.
This method tells you if this store has a grouper defined on it.
true
if this store has a grouper defined.
Returns true
if the Store is currently performing a load operation.
true
if the Store is currently loading.
Convenience function for getting the last model instance in the store.
The last model instance in the store, or undefined
.
Loads data into the Store via the configured proxy. This uses the Proxy to make an asynchronous call to whatever storage backend the Proxy uses, automatically adding the retrieved instances into the Store and calling an optional callback if required. Example usage:
store.load({
callback: function(records, operation, success) {
// the operation object contains all of the details of the load operation
console.log(records);
},
scope: this
});
If only the callback and scope options need to be specified, then one can call it simply like so:
store.load(function(records, operation, success) {
console.log('loaded records');
}, this);
config object, passed into the Ext.data.Operation object before loading.
Scope for the function.
Loads an array of data straight into the Store.
Array of data to load. Any non-model instances will be cast into model instances first.
true
to add the records to the existing records in the store, false
to remove the old ones first.
Loads a given 'page' of data by setting the start and limit values appropriately. Internally this just causes a normal
load operation, passing in calculated start
and limit
params.
Adds Model instance to the Store. This method accepts either:
The new Model instances will be added at the end of the existing collection.
Sample usage:
myStore.add({some: 'data2'}, {some: 'other data2'});
Use addData method instead if you have raw data that need to pass through the data reader.
This method has been deprecated since 2.0.0
Please use add instead.
An array of Model instances or Model configuration objects, or variable number of Model instance or config arguments.
The model instances that were added.
Alias for addManagedListener.
This method has been deprecated since 2.0.0
This is now done automatically
The item to which to add a listener/listeners.
The event name, or an object containing event name properties.
If the eventName
parameter was an event name, this is the handler function.
If the eventName
parameter was an event name, this is the scope in which
the handler function is executed.
If the eventName
parameter was an event name, this is the
addListener options.
Alias for removeManagedListener.
This method has been deprecated since 2.0.0
This is now done automatically
The item to which to add a listener/listeners.
The event name, or an object containing event name properties.
If the eventName
parameter was an event name, this is the handler function.
If the eventName
parameter was an event name, this is the scope in which
the handler function is executed.
Loads the next 'page' in the current data set.
Alias for addListener.
The name of the event to listen for. May also be an object who's property names are event names.
The method the event invokes. Will be called with arguments given to
fireEvent plus the options
parameter described below.
The scope (this
reference) in which the handler function is executed. If
omitted, defaults to the object which fired the event.
An object containing handler configuration.
This object may contain any of the following properties:
The scope (this
reference) in which the handler function is executed. If omitted, defaults to the object
which fired the event.
The number of milliseconds to delay the invocation of the handler after the event fires.
true
to add a handler to handle just the next firing of the event, and then remove itself.
The order of when the listener should be added into the listener queue.
If you set an order of before
and the event you are listening to is preventable, you can return false
and it will stop the event.
Available options are before
, current
and after
.
Defaults to: current
Causes the handler to be delayed by the specified number of milliseconds. If the event fires again within that time, the original handler is not invoked, but the new handler is scheduled in its place.
Allows you to add a listener onto a element of this component using the elements reference.
Ext.create('Ext.Component', {
listeners: {
element: 'element',
tap: function() {
alert('element tap!');
}
}
});
All components have the element
reference, which is the outer most element of the component. Ext.Container also has the
innerElement
element which contains all children. In most cases element
is adequate.
Uses Ext.ComponentQuery to delegate events to a specified query selector within this item.
// Create a container with a two children; a button and a toolbar
var container = Ext.create('Ext.Container', {
items: [
{
xtype: 'toolbar',
docked: 'top',
title: 'My Toolbar'
},
{
xtype: 'button',
text: 'My Button'
}
]
});
container.addListener({
// Ext.Buttons have an xtype of 'button', so we use that are a selector for our delegate
delegate: 'button',
tap: function() {
alert('Button tapped!');
}
});
The order of when the listener should be added into the listener queue.
Possible values are before
, current
and after
.
Defaults to: 'current'
Loads the previous 'page' in the current data set.
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.
The function to be called. It will be passed the following parameters:
The record to test for filtering. Access field values using Ext.data.Model.get.
The ID of the Record passed.
The scope (this
reference) in which the function is executed. Defaults to this Store.
Returns an Ext.util.MixedCollection of the matched records.
Removes the given record from the Store, firing the removerecords
event passing all the instances that are removed.
Model instance or array of instances to remove.
Removes a before-event handler.
Same as removeListener with order
set to 'after'
.
The name of the event the handler was associated with.
The handler to remove.
The scope originally specified for fn
.
Extra options object.
Remove all items from the store.
Prevent the clear
event from being fired.
Removes a before-event handler.
Same as removeListener with order
set to 'before'
.
The name of the event the handler was associated with.
The handler to remove.
The scope originally specified for fn
.
Extra options object.
Removes an event handler.
The type of event the handler was associated with.
The handler to remove. This must be a reference to the function passed into the addListener call.
The scope originally specified for the handler. It must be the same as the scope argument specified in the original call to addListener or the listener will not be removed.
Extra options object. See addListener for details.
The order of the listener to remove.
Possible values are before
, current
and after
.
Defaults to: 'current'
Adds listeners to any Observable object (or Element) which are automatically removed when this Component is destroyed.
This method has been deprecated since 2.0
All listeners are now automatically managed where necessary. Simply use removeListener.
The item to which to add a listener/listeners.
The event name, or an object containing event name properties.
If the eventName
parameter was an event name, this is the handler function.
If the eventName
parameter was an event name, this is the scope in which
the handler function is executed.
Resumes firing events (see suspendEvents).
Pass as true to discard any queued events.
Sets the value of getGroupString.
This method has been deprecated
Sorts the data in the Store by one or more of its properties. Example usage:
// sort by a single field
myStore.sort('myField', 'DESC');
// sorting by multiple fields
myStore.sort([
{
property : 'age',
direction: 'ASC'
},
{
property : 'name',
direction: 'DESC'
}
]);
Internally, Store converts the passed arguments into an array of Ext.util.Sorter instances, and delegates the actual sorting to its internal Ext.util.Collection.
When passing a single string argument to sort, Store maintains a ASC/DESC toggler per field, so this code:
store.sort('myField');
store.sort('myField');
is equivalent to this code:
store.sort('myField', 'ASC');
store.sort('myField', 'DESC');
because Store handles the toggling automatically.
If the remoteSort configuration has been set to true
, you will have to manually call the load
method after you sort to retrieve the sorted data from the server.
Either a string name of one of the fields in this Store's configured Model, or an array of sorter configurations.
The default overall direction to sort the data by.
Defaults to: ASC
This can be either 'prepend'
or 'append'
. If you leave this undefined
it will clear the current sorters.
Get the reference to the class from which this object was instantiated. Note that unlike self,
this.statics()
is scope-independent and it always returns the class from which it was called, regardless of what
this
points to during run-time
Ext.define('My.Cat', {
statics: {
totalCreated: 0,
speciesName: 'Cat' // My.Cat.speciesName = 'Cat'
},
constructor: function() {
var statics = this.statics();
alert(statics.speciesName); // always equals to 'Cat' no matter what 'this' refers to
// equivalent to: My.Cat.speciesName
alert(this.self.speciesName); // dependent on 'this'
statics.totalCreated++;
},
clone: function() {
var cloned = new this.self(); // dependent on 'this'
cloned.groupName = this.statics().speciesName; // equivalent to: My.Cat.speciesName
return cloned;
}
});
Ext.define('My.SnowLeopard', {
extend: 'My.Cat',
statics: {
speciesName: 'Snow Leopard' // My.SnowLeopard.speciesName = 'Snow Leopard'
},
constructor: function() {
this.callParent();
}
});
var cat = new My.Cat(); // alerts 'Cat', then alerts 'Cat'
var snowLeopard = new My.SnowLeopard(); // alerts 'Cat', then alerts 'Snow Leopard'
var clone = snowLeopard.clone();
alert(Ext.getClassName(clone)); // alerts 'My.SnowLeopard'
alert(clone.groupName); // alerts 'Cat'
alert(My.Cat.totalCreated); // alerts 3
Suspends the firing of all events.
All events will be queued but you can discard the queued events by passing false in the resumeEvents call
Synchronizes the Store with its Proxy. This asks the Proxy to batch together any new, updated and deleted records in the store, updating the Store's internal representation of the records as each operation completes.
Alias for removeListener.
The type of event the handler was associated with.
The handler to remove. This must be a reference to the function passed into the addListener call.
The scope originally specified for the handler. It must be the same as the scope argument specified in the original call to addListener or the listener will not be removed.
Extra options object. See addListener for details.
The order of the listener to remove.
Possible values are before
, current
and after
.
Defaults to: 'current'
Add methods / properties to the prototype of this class.
Ext.define('My.awesome.Cat', {
constructor: function() {
// ...
}
});
My.awesome.Cat.addMembers({
meow: function() {
alert('Meowww...');
}
});
var kitty = new My.awesome.Cat();
kitty.meow();
Add / override static properties of this class.
Ext.define('My.cool.Class', {
// this.se
});
My.cool.Class.addStatics({
someProperty: 'someValue', // My.cool.Class.someProperty = 'someValue'
method1: function() { }, // My.cool.Class.method1 = function() { ... };
method2: function() { } // My.cool.Class.method2 = function() { ... };
});
this
Borrow another class' members to the prototype of this class.
Ext.define('Bank', {
money: '$$$',
printMoney: function() {
alert('$$$$$$$');
}
});
Ext.define('Thief', {
// ...
});
Thief.borrow(Bank, ['money', 'printMoney']);
var steve = new Thief();
alert(steve.money); // alerts '$$$'
steve.printMoney(); // alerts '$$$$$$$'
The class to borrow members from
The names of the members to borrow
this
Create aliases for existing prototype methods. Example:
Ext.define('My.cool.Class', {
method1: function() { },
method2: function() { }
});
var test = new My.cool.Class();
My.cool.Class.createAlias({
method3: 'method1',
method4: 'method2'
});
test.method3(); // test.method1()
My.cool.Class.createAlias('method5', 'method3');
test.method5(); // test.method3() -> test.method1()
The new method name, or an object to set multiple aliases. See flexSetter
The original method name
Get the current class' name in string format.
Ext.define('My.cool.Class', {
constructor: function() {
alert(this.self.getName()); // alerts 'My.cool.Class'
}
});
My.cool.Class.getName(); // 'My.cool.Class'
className
Override members of this class. Overridden methods can be invoked via callParent.
Ext.define('My.Cat', {
constructor: function() {
alert("I'm a cat!");
}
});
My.Cat.override({
constructor: function() {
alert("I'm going to be a cat!");
var instance = this.callParent(arguments);
alert("Meeeeoooowwww");
return instance;
}
});
var kitty = new My.Cat(); // alerts "I'm going to be a cat!"
// alerts "I'm a cat!"
// alerts "Meeeeoooowwww"
As of 2.1, direct use of this method is deprecated. Use Ext.define instead:
Ext.define('My.CatOverride', {
override: 'My.Cat',
constructor: function() {
alert("I'm going to be a cat!");
var instance = this.callParent(arguments);
alert("Meeeeoooowwww");
return instance;
}
});
The above accomplishes the same result but can be managed by the Ext.Loader which can properly order the override and its target class and the build process can determine whether the override is needed based on the required state of the target class (My.Cat).
This method has been deprecated since 2.1.0
Please use Ext.define instead
The properties to add to this class. This should be specified as an object literal containing one or more properties.
this class
Fired when one or more new Model instances have been added to this Store. You should listen for this event if you have to update a representation of the records in this store in your UI. If you need the indices of the records that were added please use the store.indexOf(record) method.
The store
The Model instances that were added
The options object passed to Ext.util.Observable.addListener.
Fires before a request is made for a new data object. If the beforeload handler returns false the load action will be canceled. Note that you should not listen for this event in order to refresh the data view. Use the refresh event for this instead.
This Store
The Ext.data.Operation object that will be passed to the Proxy to load the Store
The options object passed to Ext.util.Observable.addListener.
Fired before a call to sync is executed. Return false
from any listener to cancel the sync
Hash of all records to be synchronized, broken down into create, update and destroy
The options object passed to Ext.util.Observable.addListener.
Fired after the removeAll method is called. Note that you should not listen for this event in order to refresh the data view. Use the refresh event for this instead.
The options object passed to Ext.util.Observable.addListener.
Fires whenever records have been loaded into the store. Note that you should not listen for this event in order to refresh the data view. Use the refresh event for this instead.
An array of records
true
if the operation was successful.
The associated operation.
The options object passed to Ext.util.Observable.addListener.
Fires whenever the server has sent back new metadata to reconfigure the Reader.
The metadata sent back from the server.
The options object passed to Ext.util.Observable.addListener.
Fires whenever the records in the Store have changed in a way that your representation of the records need to be entirely refreshed.
The data store
The data collection containing all the records
The options object passed to Ext.util.Observable.addListener.
Fired when one or more Model instances have been removed from this Store. You should listen for this event if you have to update a representation of the records in this store in your UI.
The Store object
The Model instances that was removed
The indices of the records that were removed. These indices already take into account any potential earlier records that you remove. This means that if you loop over the records, you can get its current index in your data representation from this array.
The options object passed to Ext.util.Observable.addListener.
Fires when a Model instance has been updated
This event has been removed since 2.0
Listen to updaterecord instead.
The Model instance that was updated
If the update changed the index of the record (due to sorting for example), then this gives you the new index in the store.
If the update changed the index of the record (due to sorting for example), then this gives you the old index in the store.
An array containing the field names that have been modified since the record was committed or created
An object where each key represents a field name that had it's value modified, and where the value represents the old value for that field. To get the new value in a listener you should use the get method.
The options object passed to Ext.util.Observable.addListener.
Fires when a Model instance has been updated
The Model instance that was updated
If the update changed the index of the record (due to sorting for example), then this gives you the new index in the store.
If the update changed the index of the record (due to sorting for example), then this gives you the old index in the store.
An array containing the field names that have been modified since the record was committed or created
An object where each key represents a field name that had it's value modified, and where the value represents the old value for that field. To get the new value in a listener you should use the get method.
The options object passed to Ext.util.Observable.addListener.
Fires whenever a successful write has been made via the configured Proxy
This Store
The Operation object that was used in the write
The options object passed to Ext.util.Observable.addListener.