Ext JS 3.4.0 Sencha Docs

Ext.util.MixedCollection

Hierarchy

Ext.util.Observable
Ext.util.MixedCollection

Subclasses

Files

A Collection class that maintains both numeric indexes and keys and exposes events.

Available since: 1.1.0

Defined By

Config options

Ext.util.MixedCollection
view source
: Boolean
Specify true if the addAll function should add function references to the collection. ...

Specify true if the addAll function should add function references to the collection. Defaults to false.

Defaults to: false

Available since: Ext JS 3.4.0

(optional) A config object containing one or more event handlers to be added to this object during initialization. ...

(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 Component's HTMLElement, listeners must be added to the Element after the Component has been rendered. A plugin can simplify this step:

// Plugin is configured with a listeners config object.
// The Component is appended to the argument list of all handler functions.
Ext.DomObserver = Ext.extend(Object, {
    constructor: function(config) {
        this.listeners = config.listeners ? config.listeners : config;
    },

    // Component passes itself into plugin's init method
    init: function(c) {
        var p, l = this.listeners;
        for (p in l) {
            if (Ext.isFunction(l[p])) {
                l[p] = this.createHandler(l[p], c);
            } else {
                l[p].fn = this.createHandler(l[p].fn, c);
            }
        }

        // Add the listeners to the Element immediately following the render call
        c.render = c.render.createSequence(function() {
            var e = c.getEl();
            if (e) {
                e.on(l);
            }
        });
    },

    createHandler: function(fn, c) {
        return function(e) {
            fn.call(this, e, c);
        };
    }
});

var combo = new Ext.form.ComboBox({

    // Collapse combo when its element is clicked on
    plugins: [ new Ext.DomObserver({
        click: function(evt, comp) {
            comp.collapse();
        }
    })],
    store: myStore,
    typeAhead: true,
    mode: 'local',
    triggerAction: 'all'
});

Available since: 1.1.0

Defined By

Methods

Ext.util.MixedCollection
view source
new( allowFunctions, keyFn ) : Ext.util.MixedCollection
...

Available since: 1.1.0

Parameters

  • allowFunctions : Boolean

    Specify true if the addAll function should add function references to the collection. Defaults to false.

  • keyFn : Function

    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.

Returns

Ext.util.MixedCollection
view source
( property, [dir], [fn] )private
Performs the actual sorting based on a direction and a sorting function. ...

Performs the actual sorting based on a direction and a sorting function. Internally, this creates a temporary array of all items in the MixedCollection, sorts it and then writes the sorted array data back into this.items and this.keys

Available since: Ext JS 3.4.0

Parameters

  • property : String

    Property to sort by ('key', 'value', or 'index')

  • dir : String (optional)

    Direction to sort 'ASC' or 'DESC'. Defaults to 'ASC'.

  • fn : Function (optional)

    Comparison function that defines the sort order. Defaults to sorting by numeric value.

Fires

  • sort
Ext.util.MixedCollection
view source
( key, o ) : Object
Adds an item to the collection. ...

Adds an item to the collection. Fires the add event when complete.

Available since: 1.1.0

Parameters

  • key : String

    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.

  • o : Object

    The item to add.

Returns

  • Object

    The item added.

Fires

Ext.util.MixedCollection
view source
( objs )
Adds all elements of an Array or an Object to the collection. ...

Adds all elements of an Array or an Object to the collection.

Available since: 1.1.0

Parameters

  • objs : Object/Array

    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.

Fires

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.

Available since: 1.1.0

Parameters

  • o : Object|String

    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.

  • Optional : string

    . Event name if multiple event names are being passed as separate parameters. Usage:

    this.addEvents('storeloaded', 'storecleared');
    
( eventName, handler, [scope], [options] )
Appends an event handler to this object. ...

Appends an event handler to this object.

Available since: 1.1.0

Parameters

  • eventName : String

    The name of the event to listen for.

  • handler : Function

    The method the event invokes.

  • scope : Object (optional)

    The scope (this reference) in which the handler function is executed. If omitted, defaults to the object which fired the event.

  • options : Object (optional)

    An object containing handler configuration. properties. This may contain any of the following properties:

    • scope : Object
      The scope (this reference) in which the handler function is executed. If omitted, defaults to the object which fired the event.
    • delay : Number
      The number of milliseconds to delay the invocation of the handler after the event fires.
    • single : Boolean
      True to add a handler to handle just the next firing of the event, and then remove itself.
    • buffer : Number
      Causes the handler to be scheduled to run in an Ext.util.DelayedTask 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.
    • target : Observable
      Only call the handler if the event was fired on the target Observable, not if the event was bubbled up from a child Observable.

    Combining Options
    Using the options argument, it is possible to combine different types of listeners:

    A delayed, one-time listener.

    myDataView.on('click', this.onClick, 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 handlers.

    myGridPanel.on({
    'click' : {
        fn: this.onClick,
        scope: this,
        delay: 100
    },
    'mouseover' : {
        fn: this.onMouseOver,
        scope: this
    },
    'mouseout' : {
        fn: this.onMouseOut,
        scope: this
    }
    });

    Or a shorthand syntax:

    myGridPanel.on({
    'click' : this.onClick,
    'mouseover' : this.onMouseOver,
    'mouseout' : this.onMouseOut,
     scope: this
    });

Fires

    Ext.util.MixedCollection
    view source
    ( )
    Removes all items from the collection. ...

    Removes all items from the collection. Fires the clear event when complete.

    Available since: 1.1.0

    Fires

    Ext.util.MixedCollection
    view source
    ( ) : MixedCollection
    Creates a shallow copy of this collection ...

    Creates a shallow copy of this collection

    Available since: 1.1.0

    Returns

    • MixedCollection
    Ext.util.MixedCollection
    view source
    ( o ) : Boolean
    Returns true if the collection contains the passed Object as an item. ...

    Returns true if the collection contains the passed Object as an item.

    Available since: 1.1.0

    Parameters

    • o : Object

      The Object to look for in the collection.

    Returns

    • Boolean

      True if the collection contains the Object as an item.

    Fires

      Ext.util.MixedCollection
      view source
      ( key ) : Boolean
      Returns true if the collection contains the passed Object as a key. ...

      Returns true if the collection contains the passed Object as a key.

      Available since: 1.1.0

      Parameters

      • key : String

        The key to look for in the collection.

      Returns

      • Boolean

        True if the collection contains the Object as a key.

      Ext.util.MixedCollection
      view source
      ( value, anyMatch, caseSensitive, exactMatch )private
      Returns a regular expression based on the given value and matching options. ...

      Returns a regular expression based on the given value and matching options. This is used internally for finding and filtering, and by Ext.data.Store.filter

      Available since: Ext JS 3.4.0

      Parameters

      • value : String

        The value to create the regex for. This is escaped using Ext.escapeRe

      • anyMatch : Boolean

        True to allow any match - no regex start/end line anchors will be added. Defaults to false

      • caseSensitive : Boolean

        True to make the regex case sensitive (adds 'i' switch to regex). Defaults to false.

      • exactMatch : Boolean

        True to force exact match (^ and $ characters added to the regex). Defaults to false. Ignored if anyMatch is true.

      Ext.util.MixedCollection
      view source
      ( fn, [scope] )
      Executes the specified function once for every item in the collection, passing the following arguments: item : Mixe...

      Executes the specified function once for every item in the collection, passing the following arguments:

      • item : Mixed

        The collection item

      • index : Number

        The item's index

      • length : Number

        The total number of items in the collection

      The function should return a boolean value. Returning false from the function will stop the iteration.

      Available since: 1.1.0

      Parameters

      • fn : Function

        The function to execute for each item.

      • scope : Object (optional)

        The scope (this reference) in which the function is executed. Defaults to the current item in the iteration.

      Ext.util.MixedCollection
      view source
      ( fn, [scope] )
      Executes the specified function once for every key in the collection, passing each key, and its associated item as th...

      Executes the specified function once for every key in the collection, passing each key, and its associated item as the first two parameters.

      Available since: 1.1.0

      Parameters

      • fn : Function

        The function to execute for each item.

      • scope : Object (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. ...

      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, {
          //  Add functionality to Field's initComponent to enable the change event to bubble
          initComponent : Ext.form.Field.prototype.initComponent.createSequence(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');
              }
          }
      });
      

      Available since: Ext JS 3.4.0

      Parameters

      • events : String/Array

        The event name to bubble, or an Array of event names.

      Ext.util.MixedCollection
      view source
      ( property, value, [anyMatch], [caseSensitive] ) : MixedCollection
      Filter the objects in this collection by a specific property. ...

      Filter the objects in this collection by a specific property. Returns a new collection that has been filtered.

      Available since: 1.1.0

      Parameters

      • property : String

        A property on your objects

      • value : String/RegExp

        Either string that the property values should start with or a RegExp to test against the property

      • anyMatch : Boolean (optional)

        True to match any part of the string, not just the beginning

      • caseSensitive : Boolean (optional)

        True for case sensitive comparison (defaults to False).

      Returns

      • MixedCollection

        The new filtered collection

      Fires

        Ext.util.MixedCollection
        view source
        ( fn, [scope] ) : MixedCollection
        Filter by a function. ...

        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.

        Available since: 1.1.0

        Parameters

        • fn : Function

          The function to be called, it will receive the args o (the object), k (the key)

        • scope : Object (optional)

          The scope (this reference) in which the function is executed. Defaults to this MixedCollection.

        Returns

        • MixedCollection

          The new filtered collection

        Ext.util.MixedCollection
        view source
        ( fn, [scope] ) : Object
        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.

        Available since: 1.1.0

        Parameters

        • fn : Function

          The selection function to execute for each item.

        • scope : Object (optional)

          The scope (this reference) in which the function is executed. Defaults to the browser window.

        Returns

        • Object

          The first item in the collection which returned true from the selection function.

        Ext.util.MixedCollection
        view source
        ( property, value, [start], [anyMatch], [caseSensitive] ) : Number
        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.

        Available since: 2.3.0

        Parameters

        • property : String

          The name of a property on your objects.

        • value : String/RegExp

          A string that the property values should start with or a RegExp to test against the property.

        • start : Number (optional)

          The index to start searching at (defaults to 0).

        • anyMatch : Boolean (optional)

          True to match any part of the string, not just the beginning.

        • caseSensitive : Boolean (optional)

          True for case sensitive comparison.

        Returns

        • Number

          The matched index or -1

        Fires

          Ext.util.MixedCollection
          view source
          ( fn, [scope], [start] ) : Number
          Find the index of the first matching object in this collection by a function. ...

          Find the index of the first matching object in this collection by a function. If the function returns true it is considered a match.

          Available since: 2.3.0

          Parameters

          • fn : Function

            The function to be called, it will receive the args o (the object), k (the key).

          • scope : Object (optional)

            The scope (this reference) in which the function is executed. Defaults to this MixedCollection.

          • start : Number (optional)

            The index to start searching at (defaults to 0).

          Returns

          • Number

            The matched index or -1

          ( eventName, args ) : Boolean
          Fires the specified event with the passed parameters (minus the event name). ...

          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.

          Available since: 1.1.0

          Parameters

          • eventName : String

            The name of the event to fire.

          • args : Object...

            Variable number of parameters are passed to handlers.

          Returns

          • Boolean

            returns false if any of the handlers return false otherwise it returns true.

          Fires

            Ext.util.MixedCollection
            view source
            ( ) : Object
            Returns the first item in the collection. ...

            Returns the first item in the collection.

            Available since: 1.1.0

            Returns

            • Object

              the first item in the collection..

            Ext.util.MixedCollection
            view source
            ( key ) : Object
            This method calls item(). ...

            This method calls item(). 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 itemAt.

            Available since: 1.1.0

            Parameters

            Returns

            • Object

              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.

            Ext.util.MixedCollection
            view source
            ( ) : Number
            Returns the number of items in the collection. ...

            Returns the number of items in the collection.

            Available since: 1.1.0

            Returns

            • Number

              the number of items in the collection.

            Ext.util.MixedCollection
            view source
            ( item ) : Object
            MixedCollection has a generic way to fetch keys if you implement getKey. ...

            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);
            

            Available since: 1.1.0

            Parameters

            • item : Object

              The item for which to find the key.

            Returns

            • Object

              The key for the passed item.

            Ext.util.MixedCollection
            view source
            ( [startIndex], [endIndex] ) : Array
            Returns a range of items in this collection ...

            Returns a range of items in this collection

            Available since: 1.1.0

            Parameters

            • startIndex : Number (optional)

              The starting index. Defaults to 0.

            • endIndex : Number (optional)

              The ending index. Defaults to the last item.

            Returns

            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

            Available since: 1.1.0

            Parameters

            • eventName : String

              The name of the event to check for

            Returns

            • Boolean

              True if the event is being listened for, else false

            Ext.util.MixedCollection
            view source
            ( o ) : Number
            Returns index within the collection of the passed Object. ...

            Returns index within the collection of the passed Object.

            Available since: 1.1.0

            Parameters

            • o : Object

              The item to find the index of.

            Returns

            • Number

              index of the item. Returns -1 if not found.

            Ext.util.MixedCollection
            view source
            ( key ) : Number
            Returns index within the collection of the passed key. ...

            Returns index within the collection of the passed key.

            Available since: 1.1.0

            Parameters

            • key : String

              The key to find the index of.

            Returns

            Ext.util.MixedCollection
            view source
            ( index, key, [o] ) : Object
            Inserts an item at the specified index in the collection. ...

            Inserts an item at the specified index in the collection. Fires the add event when complete.

            Available since: 1.1.0

            Parameters

            • index : Number

              The index to insert the item at.

            • key : String

              The key to associate with the new item, or the item itself.

            • o : Object (optional)

              If the second parameter was a key, the new item.

            Returns

            • Object

              The item inserted.

            Fires

            Ext.util.MixedCollection
            view source
            ( key ) : Object
            Returns the item associated with the passed key OR index. ...

            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 itemAt.

            Available since: 1.1.0

            Parameters

            Returns

            • Object

              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.

            Ext.util.MixedCollection
            view source
            ( index ) : Object
            Returns the item at the specified index. ...

            Returns the item at the specified index.

            Available since: 1.1.0

            Parameters

            • index : Number

              The index of the item.

            Returns

            • Object

              The item at the specified index.

            Ext.util.MixedCollection
            view source
            ( key ) : Object
            Returns the item associated with the passed key. ...

            Returns the item associated with the passed key.

            Available since: 1.1.0

            Parameters

            Returns

            • Object

              The item associated with the passed key.

            Ext.util.MixedCollection
            view source
            ( [direction], [fn] )
            Sorts this collection by keys. ...

            Sorts this collection by keys.

            Available since: 1.1.0

            Parameters

            • direction : String (optional)

              'ASC' or 'DESC'. Defaults to 'ASC'.

            • fn : Function (optional)

              Comparison function that defines the sort order. Defaults to sorting by case insensitive string.

            Fires

            • sort
            Ext.util.MixedCollection
            view source
            ( ) : Object
            Returns the last item in the collection. ...

            Returns the last item in the collection.

            Available since: 1.1.0

            Returns

            • Object

              the last item in the collection..

            ( eventName, handler, [scope], [options] )
            Appends an event handler to this object (shorthand for addListener.) ...

            Appends an event handler to this object (shorthand for addListener.)

            Available since: 1.1.0

            Parameters

            • eventName : String

              The type of event to listen for

            • handler : Function

              The method the event invokes

            • scope : Object (optional)

              The scope (this reference) in which the handler function is executed. If omitted, defaults to the object which fired the event.

            • options : Object (optional)

              An object containing handler configuration.

            Removes all listeners for this object ...

            Removes all listeners for this object

            Available since: 1.1.0

            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.

            Available since: 2.3.0

            Parameters

            • o : Object

              The Observable whose events this object is to relay.

            • events : Array

              Array of event names to relay.

            Ext.util.MixedCollection
            view source
            ( o ) : Object
            Remove an item from the collection. ...

            Remove an item from the collection.

            Available since: 1.1.0

            Parameters

            • o : Object

              The item to remove.

            Returns

            • Object

              The item removed or false if no item was removed.

            Fires

            Ext.util.MixedCollection
            view source
            ( index ) : Object
            Remove an item from a specified index in the collection. ...

            Remove an item from a specified index in the collection. Fires the remove event when complete.

            Available since: 1.1.0

            Parameters

            • index : Number

              The index within the collection of the item to remove.

            Returns

            • Object

              The item removed or false if no item was removed.

            Fires

            Ext.util.MixedCollection
            view source
            ( key ) : Object
            Removed an item associated with the passed key fom the collection. ...

            Removed an item associated with the passed key fom the collection.

            Available since: 1.1.0

            Parameters

            • key : String

              The key of the item to remove.

            Returns

            • Object

              The item removed or false if no item was removed.

            Fires

            ( eventName, handler, [scope] )
            Removes an event handler. ...

            Removes an event handler.

            Available since: 1.1.0

            Parameters

            • eventName : String

              The type of event the handler was associated with.

            • handler : Function

              The handler to remove. This must be a reference to the function passed into the addListener call.

            • scope : Object (optional)

              The scope originally specified for the handler.

            Ext.util.MixedCollection
            view source
            ( mapping )
            Reorders each of the items based on a mapping from old index to new index. ...

            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.

            Available since: Ext JS 3.4.0

            Parameters

            • mapping : Object

              Mapping from old item index to new item index

            Fires

            Ext.util.MixedCollection
            view source
            ( key, o ) : Object
            Replaces an item in the collection. ...

            Replaces an item in the collection. Fires the replace event when complete.

            Available since: 1.1.0

            Parameters

            • key : String

              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.

            • o : Object

              {Object} o (optional) If the first parameter passed was a key, the item to associate with that key.

            Returns

            • Object

              The new item.

            Fires

            Resume firing events. ...

            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.

            Available since: 2.3.0

            Ext.util.MixedCollection
            view source
            ( [direction], [fn] )
            Sorts this collection by item value with the passed comparison function. ...

            Sorts this collection by item value with the passed comparison function.

            Available since: 1.1.0

            Parameters

            • direction : String (optional)

              'ASC' or 'DESC'. Defaults to 'ASC'.

            • fn : Function (optional)

              Comparison function that defines the sort order. Defaults to sorting by numeric value.

            Fires

            • sort
            Suspend the firing of all events. ...

            Suspend the firing of all events. (see resumeEvents)

            Available since: 2.3.0

            Parameters

            • queueSuspended : Boolean

              Pass as true to queue up suspended events to be fired after the resumeEvents call instead of discarding all suspended events;

            ( eventName, handler, [scope] )
            Removes an event handler (shorthand for removeListener.) ...

            Removes an event handler (shorthand for removeListener.)

            Available since: 1.1.0

            Parameters

            • eventName : String

              The type of event the handler was associated with.

            • handler : Function

              The handler to remove. This must be a reference to the function passed into the addListener call.

            • scope : Object (optional)

              The scope originally specified for the handler.

            Defined By

            Events

            Ext.util.MixedCollection
            view source
            ( index, o, key )
            Fires when an item is added to the collection. ...

            Fires when an item is added to the collection.

            Available since: 1.1.0

            Parameters

            • index : Number

              The index at which the item was added.

            • o : Object

              The item added.

            • key : String

              The key associated with the added item.

            Ext.util.MixedCollection
            view source
            ( )
            Fires when the collection is cleared. ...

            Fires when the collection is cleared.

            Available since: 1.1.0

            Ext.util.MixedCollection
            view source
            ( o, [key] )
            Fires when an item is removed from the collection. ...

            Fires when an item is removed from the collection.

            Available since: 1.1.0

            Parameters

            • o : Object

              The item being removed.

            • key : String (optional)

              The key associated with the removed item.

            Ext.util.MixedCollection
            view source
            ( key, old, new )
            Fires when an item is replaced in the collection. ...

            Fires when an item is replaced in the collection.

            Available since: 1.1.0

            Parameters

            • key : String

              he key associated with the new added.

            • old : Object

              The item being replaced.

            • new : Object

              The new item.