Hierarchy
Ext.util.AbstractMixedCollectionExt.util.MixedCollectionMixins
Represents a collection of a set of key and value pairs. Each key in the MixedCollection must be unique, the same key cannot exist twice. This collection is ordered, items in the collection can be accessed by index or via the key. Newly added items are added to the end of the collection. This class is similar to Ext.util.HashMap however it is heavier and provides more functionality. Sample usage:
var coll = new Ext.util.MixedCollection();
coll.add('key1', 'val1');
coll.add('key2', 'val2');
coll.add('key3', 'val3');
console.log(coll.get('key1')); // prints 'val1'
console.log(coll.indexOfKey('key3')); // prints 2
The MixedCollection also has support for sorting and filtering of the values in the collection.
var coll = new Ext.util.MixedCollection();
coll.add('key1', 100);
coll.add('key2', -100);
coll.add('key3', 17);
coll.add('key4', 0);
var biggerThanZero = coll.filterBy(function(value){
return value > 0;
});
console.log(biggerThanZero.getCount()); // prints 2
(optional)
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
click
event passing the node clicked on. To access DOM
events directly from a child element of a Component, we need to specify the element
option to
identify the Component property to add a DOM listener to:
new Ext.panel.Panel({
width: 400,
height: 200,
dockedItems: [{
xtype: 'toolbar'
}],
listeners: {
click: {
element: 'el', //bind to the underlying el property on the panel
fn: function(){ console.log('click el'); }
},
dblclick: {
element: 'body', //bind to the underlying body property on the panel
fn: function(){ console.log('dblclick body'); }
}
}
});
The default sort direction to use if one is not specified (defaults to "ASC")
The default sort direction to use if one is not specified (defaults to "ASC")
Flag denoting that this object is sortable. Always true.
Flag denoting that this object is sortable. Always true.
Specify true if the addAll function should add function references to the collection. Defaults to false.
A function that can accept an item of the type(s) stored in this MixedCollection and return the key value for that item. This is used when available to look up the key on items that were passed without an explicit key parameter to a MixedCollection method. Passing this parameter is equivalent to providing an implementation for the getKey method.
Adds an item to the collection. Fires the add event when complete.
Adds an item to the collection. Fires the add event when complete.
The key to associate with the item, or the new item.
If a getKey implementation was specified for this MixedCollection, or if the key of the stored items is in a property called id, the MixedCollection will be able to derive the key for the new item. In this case just pass the new item in this parameter.
The item to add.
The item added.
Adds all elements of an Array or an Object to the collection.
Adds all elements of an Array or an Object to the collection.
An Object containing properties which will be added
to the collection, or an Array of values, each of which are added to the collection.
Functions references will be added to the collection if allowFunctions
has been set to true.
Adds 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.
Either an object with event names as properties with a value of true
or the first event name string if multiple event names are being passed as separate parameters.
[additional] Optional additional event names if multiple event names are being passed as separate parameters. Usage:
this.addEvents('storeloaded', 'storecleared');
Appends an event handler to this object.
Appends an event handler to this object.
The name of the event to listen for. May also be an object who's property names are event names. See
The method the event invokes.
(optional) The scope (this
reference) in which the handler function is executed.
If omitted, defaults to the object which fired the event.
(optional) An object containing handler configuration. properties. This may contain any of the following properties:
this
reference) in which the handler function is executed.
If omitted, defaults to the object which fired the event.This option is useful during Component construction to add DOM event listeners to elements of Components which will exist only after the Component is rendered. For example, to add a click listener to a Panel's body:
new Ext.panel.Panel({
title: 'The title',
listeners: {
click: this.handlePanelClick,
element: 'body'
}
});
When added in this way, the options available are the options applicable to Ext.core.Element.addListener
Combining Options
Using the options argument, it is possible to combine different types of listeners:
A delayed, one-time listener.
myPanel.on('hide', this.handleClick, this, {
single: true,
delay: 100
});
Attaching multiple handlers in 1 call
The method also allows for a single argument to be passed which is a config object containing properties
which specify multiple events. For example:
myGridPanel.on({
cellClick: this.onCellClick,
mouseover: this.onMouseOver,
mouseout: this.onMouseOut,
scope: this // Important. Ensure "this" is correct during handler execution
});
.
Adds listeners to any Observable object (or Element) which are automatically removed when this Component is destroyed.
Adds listeners to any Observable object (or Element) which are automatically removed when this Component is destroyed.
The item to which to add a listener/listeners.
The event name, or an object containing event name properties.
Optional. If the ename
parameter was an event name, this
is the handler function.
Optional. If the ename
parameter was an event name, this
is the scope (this
reference) in which the handler function is executed.
Optional. If the ename
parameter was an event name, this
is the addListener options.
Starts capture on the specified Observable. All events will be passed to the supplied function with the event name + standard signature of the event before the event is fired. If the supplied function returns false, the event will not fire.
The Observable to capture events from.
The function to call when an event is fired.
(optional) The scope (this
reference) in which the function is executed. Defaults to the Observable firing the event.
Removes all listeners for this object including the managed listeners
Removes all listeners for this object including the managed listeners
Removes all managed listeners for this object.
Removes all managed listeners for this object.
Creates a shallow copy of this collection
Creates a shallow copy of this collection
Collects unique values of a particular property in this MixedCollection
Collects unique values of a particular property in this MixedCollection
The property to collect on
Optional 'root' property to extract the first argument from. This is used mainly when summing fields in records, where the fields are all stored inside the 'data' object
(optional) Pass true to allow null, undefined or empty string values
The unique values
Returns true if the collection contains the passed Object as an item.
Returns true if the collection contains the passed Object as an item.
The Object to look for in the collection.
True if the collection contains the Object as an item.
Returns true if the collection contains the passed Object as a key.
Returns true if the collection contains the passed Object as a key.
The key to look for in the collection.
True if the collection contains the Object as a key.
Executes the specified function once for every item in the collection, passing the following arguments:
The collection item
The item's index
The total number of items in the collection
The function should return a boolean value. Returning false from the function will stop the iteration.
The function to execute for each item.
(optional) The scope (this
reference) in which the function is executed. Defaults to the current item in the iteration.
Executes the specified function once for every key in the collection, passing each key, and its associated item as the first two parameters.
The function to execute for each item.
(optional) The scope (this
reference) in which the function is executed. Defaults to the browser window.
Enables events fired by this Observable to bubble up an owner hierarchy by calling
this.getBubbleTarget()
if present. There is no implementation in the Observable base class.
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:
Ext.override(Ext.form.field.Base, {
// Add functionality to Field's initComponent to enable the change event to bubble
initComponent : Ext.Function.createSequence(Ext.form.field.Base.prototype.initComponent, function() {
this.enableBubble('change');
}),
// We know that we want Field's events to bubble directly to the FormPanel.
getBubbleTarget : function() {
if (!this.formPanel) {
this.formPanel = this.findParentByType('form');
}
return this.formPanel;
}
});
var myForm = new Ext.formPanel({
title: 'User Details',
items: [{
...
}],
listeners: {
change: function() {
// Title goes red if form has been modified.
myForm.header.setStyle('color', 'red');
}
}
});
The event name to bubble, or an Array of event names.
Filters the objects in this collection by a set of Filters, or by a single property/value pair with optional parameters for substring matching and case sensitivity. See Filter for an example of using Filter objects (preferred). Alternatively, MixedCollection can be easily filtered by property like this:
//create a simple store with a few people defined
var people = new Ext.util.MixedCollection();
people.addAll([
{id: 1, age: 25, name: 'Ed'},
{id: 2, age: 24, name: 'Tommy'},
{id: 3, age: 24, name: 'Arne'},
{id: 4, age: 26, name: 'Aaron'}
]);
//a new MixedCollection containing only the items where age == 24
var middleAged = people.filter('age', 24);
A property on your objects, or an array of Filter objects
Either string that the property values should start with or a RegExp to test against the property
(optional) True to match any part of the string, not just the beginning
(optional) True for case sensitive comparison (defaults to False).
The new filtered collection
Filter by a function. Returns a new collection that has been filtered. The passed function will be called with each object in the collection. If the function returns true, the value is included otherwise it is filtered.
The function to be called, it will receive the args o (the object), k (the key)
(optional) The scope (this
reference) in which the function is executed. Defaults to this MixedCollection.
The new filtered collection
Returns the first item in the collection which elicits a true return value from the passed selection function.
Returns the first item in the collection which elicits a true return value from the passed selection function.
The selection function to execute for each item.
(optional) The scope (this
reference) in which the function is executed. Defaults to the browser window.
The first item in the collection which returned true from the selection function.
Finds the index of the first matching object in this collection by a specific property/value.
Finds the index of the first matching object in this collection by a specific property/value.
The name of a property on your objects.
A string that the property values should start with or a RegExp to test against the property.
(optional) The index to start searching at (defaults to 0).
(optional) True to match any part of the string, not just the beginning.
(optional) True for case sensitive comparison.
The matched index or -1
Find the index of the first matching object in this collection by a function. If the function returns true it is considered a match.
The function to be called, it will receive the args o (the object), k (the key).
(optional) The scope (this
reference) in which the function is executed. Defaults to this MixedCollection.
(optional) The index to start searching at (defaults to 0).
The matched index or -1
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.
The name of the event to fire.
Variable number of parameters are passed to handlers.
returns false if any of the handlers return false otherwise it returns true.
Returns the first item in the collection.
Returns the first item in the collection.
the first item in the collection..
Returns the item associated with the passed key OR index. Key has priority over index. This is the equivalent of calling key first, then if nothing matched calling getAt.
The key or index of the item.
If the item is found, returns the item. If the item was not found, returns undefined. If an item was found, but is a Class, returns null.
Returns the item at the specified index.
Returns the item at the specified index.
The index of the item.
The item at the specified index.
Returns the item associated with the passed key.
Returns the item associated with the passed key.
The key of the item.
The item associated with the passed key.
Returns the number of items in the collection.
Returns the number of items in the collection.
the number of items in the collection.
MixedCollection has a generic way to fetch keys if you implement getKey. The default implementation
simply returns item.id
but you can provide your own implementation
to return a different value as in the following examples:
// normal way
var mc = new Ext.util.MixedCollection();
mc.add(someEl.dom.id, someEl);
mc.add(otherEl.dom.id, otherEl);
//and so on
// using getKey
var mc = new Ext.util.MixedCollection();
mc.getKey = function(el){
return el.dom.id;
};
mc.add(someEl);
mc.add(otherEl);
// or via the constructor
var mc = new Ext.util.MixedCollection(false, function(el){
return el.dom.id;
});
mc.add(someEl);
mc.add(otherEl);
The item for which to find the key.
The key for the passed item.
Returns a range of items in this collection
Returns a range of items in this collection
(optional) The starting index. Defaults to 0.
(optional) The ending index. Defaults to the last item.
An array of items
Returns an object describing the current sort state of this Store.
Returns an object describing the current sort state of this Store.
The sort state of the Store. An object with two properties:
The name of the field by which the Records are sorted.
The sort order, 'ASC' or 'DESC' (case-sensitive).
Checks 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
The name of the event to check for
True if the event is being listened for, else false
Returns index within the collection of the passed Object.
Returns index within the collection of the passed Object.
The item to find the index of.
index of the item. Returns -1 if not found.
Returns index within the collection of the passed key.
Returns index within the collection of the passed key.
The key to find the index of.
index of the key.
Performs initialization of this mixin. Component classes using this mixin should call this method during their own initialization.
Inserts an item at the specified index in the collection. Fires the add event when complete.
Inserts an item at the specified index in the collection. Fires the add event when complete.
The index to insert the item at.
The key to associate with the new item, or the item itself.
(optional) If the second parameter was a key, the new item.
The item inserted.
Returns the last item in the collection.
Returns the last item in the collection.
the last item in the collection..
Sets observability on the passed class constructor.
This makes any event fired on any instance of the passed class also fire a single event through the class allowing for central handling of events on many instances at once.
Usage:
Ext.util.Observable.observe(Ext.data.Connection);
Ext.data.Connection.on('beforerequest', function(con, options) {
console.log('Ajax request made to ' + options.url);
});
The class constructor to make observable.
An object containing a series of listeners to add. See addListener.
Appends an event handler to this object (shorthand for addListener.)
Appends an event handler to this object (shorthand for addListener.)
The type of event to listen for
The method the event invokes
(optional) The scope (this
reference) in which the handler function is executed.
If omitted, defaults to the object which fired the event.
(optional) An object containing handler configuration.
Relays 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
.
The Observable whose events this object is to relay.
Array of event names to relay.
Removes all added captures from the Observable.
Removes all added captures from the Observable.
The Observable to release
Remove an item from the collection.
Remove an item from the collection.
The item to remove.
The item removed or false if no item was removed.
Remove all items in the passed array from the collection.
Remove all items in the passed array from the collection.
An array of items to be removed.
this object
Remove an item from a specified index in the collection. Fires the remove event when complete.
Remove an item from a specified index in the collection. Fires the remove event when complete.
The index within the collection of the item to remove.
The item removed or false if no item was removed.
Removed an item associated with the passed key fom the collection.
Removed an item associated with the passed key fom the collection.
The key of the item to remove.
The item removed or false if no item was removed.
Removes an event handler.
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.
(optional) The scope originally specified for the handler.
Removes listeners that were added by the mon method.
Removes listeners that were added by the mon method.
The item from which to remove a listener/listeners.
The event name, or an object containing event name properties.
Optional. If the ename
parameter was an event name, this
is the handler function.
Optional. If the ename
parameter was an event name, this
is the scope (this
reference) in which the handler function is executed.
Reorders each of the items based on a mapping from old index to new index. Internally this just translates into a sort. The 'sort' event is fired whenever reordering has occured.
Mapping from old item index to new item index
Replaces an item in the collection. Fires the replace event when complete.
Replaces an item in the collection. Fires the replace event when complete.
The key associated with the item to replace, or the replacement item.
If you supplied a getKey implementation for this MixedCollection, or if the key of your stored items is in a property called id, then the MixedCollection will be able to derive the key of the replacement item. If you want to replace an item with one having the same key value, then just pass the replacement item in this parameter.
{Object} o (optional) If the first parameter passed was a key, the item to associate with that key.
The new item.
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.
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.MixedCollection.
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, because Store handles the toggling automatically:
store.sort('myField', 'ASC');
store.sort('myField', 'DESC');
Either a string name of one of the fields in this Store's configured Model, or an Array of sorter configurations.
The overall direction to sort the data by. Defaults to "ASC".
Sorts the collection by a single sorter function
Sorts the collection by a single sorter function
The function to sort by
Sorts this collection by keys.
Sorts this collection by keys.
(optional) 'ASC' or 'DESC'. Defaults to 'ASC'.
(optional) Comparison function that defines the sort order. Defaults to sorting by case insensitive string.
Collects all of the values of the given property and returns their sum
Collects all of the values of the given property and returns their sum
The property to sum by
Optional 'root' property to extract the first argument from. This is used mainly when summing fields in records, where the fields are all stored inside the 'data' object
(optional) The record index to start at (defaults to 0)
(optional) The record index to end at (defaults to -1)
The total
Suspend the firing of all events. (see resumeEvents)
Suspend the firing of all events. (see resumeEvents)
Pass as true to queue up suspended events to be fired after the resumeEvents call instead of discarding all suspended events;
Removes an event handler (shorthand for removeListener.)
Removes an event handler (shorthand 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.
(optional) The scope originally specified for the handler.
Fires when an item is added to the collection.
Fires when an item is added to the collection.
The index at which the item was added.
The item added.
The key associated with the added item.
Fires when an item is removed from the collection.
Fires when an item is removed from the collection.
The item being removed.
(optional) The key associated with the removed item.