Properties Methods Events Config Options Direct Link

    Observable
      Updater

# Class Ext.Updater

Package: | Ext
Defined In: | UpdateManager.js
Class: | Updater
Extends: | Observable

Provides AJAX-style update capabilities for Element objects. Updater can be used to update an Ext.Element once, or you can use startAutoRefresh to set up an auto-updating Element on a specific interval.
Usage:

    var el = Ext.get("foo"); // Get Ext.Element object
    var mgr = el.getUpdater();
    mgr.update({
            url: "http://myserver.com/index.php",
            params: {
                param1: "foo",
                param2: "bar"
            }
    });
    ...
    mgr.formUpdate("myFormId", "http://myserver.com/index.php");

    // or directly (returns the same Updater instance)
    var mgr = new Ext.Updater("myElementId");
    mgr.startAutoRefresh(60, "http://myserver.com/index.php");
    mgr.on("update", myFcnNeedsToKnow);

    // short handed call directly from the element object
    Ext.get("foo").load({
            url: "bar.php",
            scripts: true,
            params: "param1=foo&param2=bar",
            text: "Loading Foo..."
    });

## Config Options

Config Options | Defined By
--- | ---

listeners : Object
A config object containing one or more event handlers to be added to this object during initialization. This should ...

A config object containing one or more event handlers to be added to this object during initialization. This should be a valid listeners config object as specified in the addListener example for attaching multiple handlers at once.

DOM events from ExtJs Components

While some ExtJs Component classes export selected DOM events (e.g. "click", "mouseover" etc), this is usually only done when extra value can be added. For example the DataView's `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'
    });

Observable

## Public Properties

Property | Defined By
--- | ---
| defaultUrl : String Cached url to use for refreshes. Overwritten every time update() is called unless "discardUrl" param is set to true. | Updater
| disableCaching : Boolean Whether to append unique parameter on get request to disable caching (defaults to Ext.Updater.defaults.disableCaching... Whether to append unique parameter on get request to disable caching (defaults to Ext.Updater.defaults.disableCaching). | Updater
| el : Ext.Element The Element object | Updater
| formUpdateDelegate : Function Delegate for formUpdate() prebound to "this", use myUpdater.formUpdateDelegate.createCallback(arg1, arg2) to bind arg... Delegate for formUpdate() prebound to "this", use myUpdater.formUpdateDelegate.createCallback(arg1, arg2) to bind arguments | Updater
| indicatorText : String Text for loading indicator (defaults to Ext.Updater.defaults.indicatorText). | Updater
| loadScripts : Boolean True to process scripts in the output (defaults to Ext.Updater.defaults.loadScripts). | Updater
| refreshDelegate : Function Delegate for refresh() prebound to "this", use myUpdater.refreshDelegate.createCallback(arg1, arg2) to bind arguments | Updater
| renderer : Object The renderer for this Updater (defaults to Ext.Updater.BasicRenderer). | Updater
| showLoadIndicator : String Whether to show indicatorText when loading (defaults to Ext.Updater.defaults.showLoadIndicator). | Updater
| sslBlankUrl : String Blank page URL to use with SSL file uploads (defaults to Ext.Updater.defaults.sslBlankUrl). | Updater
| timeout : Number Timeout for requests or form posts in seconds (defaults to Ext.Updater.defaults.timeout). | Updater
| transaction : Object Transaction object of the current executing transaction, or null if there is no active transaction. | Updater
| updateDelegate : Function Delegate for update() prebound to "this", use myUpdater.updateDelegate.createCallback(arg1, arg2) to bind arguments | Updater

## Public Methods

Method | Defined By
--- | ---

Updater( `Mixed el`, [`Boolean forceNew`] )
Create new Updater directly.
Create new Updater directly.
Parameters:

- `el` : Mixed
  The element to update
- `forceNew` : Boolean
  (optional) By default the constructor checks to see if the passed element already has an Updater and if it does it returns the same instance. This will skip that check (useful for extending this class).

Returns:

- void

Updater

Updater.updateElement( `Mixed el`, `String url`, [`String/Object params`], [`Object options`] ) : void
<static> Static convenience method. This method is deprecated in favor of el.load({url:'foo.php', ...}). Usage: Ext.Updater.up...
<static> Static convenience method. This method is deprecated in favor of el.load({url:'foo.php', ...}). Usage:

    Ext.Updater.updateElement("my-div", "stuff.php");

Parameters:

- `el` : Mixed
  The element to update
- `url` : String
  The url
- `params` : String/Object
  (optional) Url encoded param string or an object of name/value pairs
- `options` : Object
  (optional) A config object with any of the Updater properties you want to set - for example: {disableCaching:true, indicatorText: "Loading data..."}

Returns:

- void

Updater

abort() : void
Aborts the currently executing transaction, if any.
Aborts the currently executing transaction, if any.
Parameters:

- None.

Returns:

- void

Updater

addEvents( `Object|String o`, `string Optional.` ) : void
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.
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');

Returns:

- void

Observable

addListener( `String eventName`, `Function handler`, [`Object scope`], [`Object options`] ) : void
Appends an event handler to this object.
Appends an event handler to this object.
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
      });

Returns:

- void

Observable

enableBubble( `String/Array events` ) : void
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');
            }
        }
    });

Parameters:

- `events` : String/Array
  The event name to bubble, or an Array of event names.

Returns:

- void

Observable

fireEvent( `String eventName`, `Object... args` ) : Boolean
Fires the specified event with the passed parameters (minus the event name). An event may be set to bubble up an Obse...

Fires the specified event with the passed parameters (minus the event name).

An event may be set to bubble up an Observable parent hierarchy (See Ext.Component.getBubbleTarget) by calling enableBubble.

Parameters:

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

Observable

formUpdate( `String/HTMLElement form`, [`String url`], [`Boolean reset`], [`Function callback`] ) : void
Performs an asynchronous form post, updating this element with the response. If the form has the attribute enctype="<...

Performs an asynchronous form post, updating this element with the response. If the form has the attribute enctype="multipart/form-data", it assumes it's a file upload. Uses this.sslBlankUrl for SSL file uploads to prevent IE security warning.

File uploads are not performed using normal "Ajax" techniques, that is they are not performed using XMLHttpRequests. Instead the form is submitted in the standard manner with the DOM `<form>` element temporarily modified to have its target set to refer to a dynamically generated, hidden `<iframe>` which is inserted into the document but removed after the return data has been gathered.

Be aware that file upload packets, sent with the content type multipart/form-data and some server technologies (notably JEE) may require some custom processing in order to retrieve parameter names and parameter values from the packet content.

Parameters:

- `form` : String/HTMLElement
  The form Id or form element
- `url` : String
  (optional) The url to pass the form to. If omitted the action attribute on the form will be used.
- `reset` : Boolean
  (optional) Whether to try to reset the form after the update
- `callback` : Function
  (optional) Callback when transaction is complete. The following parameters are passed:
  - el : Ext.Element

    The Element being updated.

  - success : Boolean

    True for success, false for failure.

  - response : XMLHttpRequest

    The XMLHttpRequest which processed the update.

Returns:

- void

Updater

getDefaultRenderer() : void
This is an overrideable method which returns a reference to a default renderer class if none is specified when creati...
This is an overrideable method which returns a reference to a default renderer class if none is specified when creating the Ext.Updater. Defaults to Ext.Updater.BasicRenderer
Parameters:

- None.

Returns:

- void

Updater

getEl() : Ext.Element
Get the Element this Updater is bound to
Get the Element this Updater is bound to
Parameters:

- None.

Returns:

- `Ext.Element`
  The element

Updater

getRenderer() : Object
Returns the current content renderer for this Updater. See Ext.Updater.BasicRenderer.render for more details.
Returns the current content renderer for this Updater. See Ext.Updater.BasicRenderer.render for more details.
Parameters:

- None.

Returns:

- `Object`

Updater

hasListener( `String eventName` ) : Boolean
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
Parameters:

- `eventName` : String
  The name of the event to check for

Returns:

- `Boolean`
  True if the event is being listened for, else false

Observable

isAutoRefreshing() : void
Returns true if the Updater is currently set to auto refresh its content (see startAutoRefresh), otherwise false.
Returns true if the Updater is currently set to auto refresh its content (see startAutoRefresh), otherwise false.
Parameters:

- None.

Returns:

- void

Updater

isUpdating() : Boolean
Returns true if an update is in progress, otherwise false.
Returns true if an update is in progress, otherwise false.
Parameters:

- None.

Returns:

- `Boolean`

Updater

on( `String eventName`, `Function handler`, [`Object scope`], [`Object options`] ) : void
Appends an event handler to this object (shorthand for addListener.)
Appends an event handler to this object (shorthand for addListener.)
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.

Returns:

- void

Observable

purgeListeners() : void
Removes all listeners for this object
Removes all listeners for this object
Parameters:

- None.

Returns:

- void

Observable

refresh( [`Function callback`] ) : void
Refresh the element with the last used url or defaultUrl. If there is no url, it returns immediately
Refresh the element with the last used url or defaultUrl. If there is no url, it returns immediately
Parameters:

- `callback` : Function
  (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)

Returns:

- void

Updater

relayEvents( `Object o`, `Array events` ) : void
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`.
Parameters:

- `o` : Object
  The Observable whose events this object is to relay.
- `events` : Array
  Array of event names to relay.

Returns:

- void

Observable

removeListener( `String eventName`, `Function handler`, [`Object scope`] ) : void
Removes an event handler.
Removes an event handler.
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.

Returns:

- void

Observable

resumeEvents() : void
Resume firing events. (see suspendEvents) If events were suspended using the queueSuspended parameter, then all event...
Resume firing events. (see suspendEvents) If events were suspended using the `queueSuspended` parameter, then all events fired during event suspension will be sent to any listeners now.
Parameters:

- None.

Returns:

- void

Observable

setDefaultUrl( `String/Function defaultUrl` ) : void
Sets the default URL used for updates.
Sets the default URL used for updates.
Parameters:

- `defaultUrl` : String/Function
  The url or a function to call to get the url

Returns:

- void

Updater

setRenderer( `Object renderer` ) : void
Sets the content renderer for this Updater. See Ext.Updater.BasicRenderer.render for more details.
Sets the content renderer for this Updater. See Ext.Updater.BasicRenderer.render for more details.
Parameters:

- `renderer` : Object
  The object implementing the render() method

Returns:

- void

Updater

showLoading() : void
Display the element's "loading" state. By default, the element is updated with indicatorText. This method may be over...
Display the element's "loading" state. By default, the element is updated with indicatorText. This method may be overridden to perform a custom action while this Updater is actively updating its contents.
Parameters:

- None.

Returns:

- void

Updater

startAutoRefresh( `Number interval`, [`String/Object/Function url`], [`String/Object params`], [`Function callback`], [`Boolean refreshNow`] ) : void
Set this element to auto refresh. Can be canceled by calling stopAutoRefresh.
Set this element to auto refresh. Can be canceled by calling stopAutoRefresh.
Parameters:

- `interval` : Number
  How often to update (in seconds).
- `url` : String/Object/Function
  (optional) The url for this request, a config object in the same format supported by load, or a function to call to get the url (defaults to the last used url). Note that while the url used in a load call can be reused by this method, other load config options will not be reused and must be sepcified as part of a config object passed as this paramter if needed.
- `params` : String/Object
  (optional) The parameters to pass as either a url encoded string "¶m1=1¶m2=2" or as an object {param1: 1, param2: 2}
- `callback` : Function
  (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
- `refreshNow` : Boolean
  (optional) Whether to execute the refresh now, or wait the interval

Returns:

- void

Updater

stopAutoRefresh() : void
Stop auto refresh on this element.
Stop auto refresh on this element.
Parameters:

- None.

Returns:

- void

Updater

suspendEvents( `Boolean queueSuspended` ) : void
Suspend the firing of all events. (see resumeEvents)
Suspend the firing of all events. (see resumeEvents)
Parameters:

- `queueSuspended` : Boolean
  Pass as true to queue up suspended events to be fired after the resumeEvents call instead of discarding all suspended events;

Returns:

- void

Observable

un( `String eventName`, `Function handler`, [`Object scope`] ) : void
Removes an event handler (shorthand for removeListener.)
Removes an event handler (shorthand for removeListener.)
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.

Returns:

- void

Observable

update( `Object options` ) : void
Performs an asynchronous request, updating this element with the response. If params are specified it uses POST, othe...
Performs an asynchronous request, updating this element with the response. If params are specified it uses POST, otherwise it uses GET.
Note: Due to the asynchronous nature of remote server requests, the Element will not have been fully updated when the function returns. To post-process the returned data, use the callback option, or an `update` event handler.
Parameters:

- `options` : Object
  A config object containing any of the following options:
  - url : String/Function

    The URL to request or a function which returns the URL (defaults to the value of Ext.Ajax.url if not specified).

  - method : String

    The HTTP method to use. Defaults to POST if the `params` argument is present, otherwise GET.

  - params : String/Object/Function

    The parameters to pass to the server (defaults to none). These may be specified as a url-encoded string, or as an object containing properties which represent parameters, or as a function, which returns such an object.

  - scripts : Boolean

    If `true` any <script> tags embedded in the response text will be extracted and executed (defaults to Ext.Updater.defaults.loadScripts). If this option is specified, the callback will be called after the execution of the scripts.

  - callback : Function

    A function to be called when the response from the server arrives. The following parameters are passed:

    - el : Ext.Element

      The Element being updated.

    - success : Boolean

      True for success, false for failure.

    - response : XMLHttpRequest

      The XMLHttpRequest which processed the update.

    - options : Object

      The config object passed to the update call.

  - scope : Object

    The scope in which to execute the callback (The callback's `this` reference.) If the `params` argument is a function, this scope is used for that function also.

  - discardUrl : Boolean

    By default, the URL of this request becomes the default URL for this Updater object, and will be subsequently used in refresh calls. To bypass this behavior, pass `discardUrl:true` (defaults to false).

  - timeout : Number

    The number of seconds to wait for a response before timing out (defaults to Ext.Updater.defaults.timeout).

  - text : String

    The text to use as the innerHTML of the Ext.Updater.defaults.indicatorText div (defaults to 'Loading...'). To replace the entire div, not just the text, override Ext.Updater.defaults.indicatorText directly.

  - nocache : Boolean

    Only needed for GET requests, this option causes an extra, auto-generated parameter to be appended to the request to defeat caching (defaults to Ext.Updater.defaults.disableCaching).

  For example:

      um.update({
              url: "your-url.php",
              params: {param1: "foo", param2: "bar"}, // or a URL encoded string
              callback: yourFunction,
              scope: yourObject, //(optional scope)
              discardUrl: true,
              nocache: true,
              text: "Loading...",
              timeout: 60,
              scripts: false // Save time by avoiding RegExp execution.
          });

Returns:

- void

Updater

## Public Events

Event | Defined By
--- | ---

beforeupdate : ( `Ext.Element el`, `String/Object/Function url`, `String/Object params` )
Fired before an update is made, return false from your handler and the update is cancelled.
Fired before an update is made, return false from your handler and the update is cancelled.
Listeners will be called with the following arguments:

- `el` : Ext.Element
- `url` : String/Object/Function
- `params` : String/Object

Updater

failure : ( `Ext.Element el`, `Object oResponseObject` )
Fired on update failure.
Fired on update failure.
Listeners will be called with the following arguments:

- `el` : Ext.Element
- `oResponseObject` : Object
  The response Object

Updater

update : ( `Ext.Element el`, `Object oResponseObject` )
Fired after successful update is made.
Fired after successful update is made.
Listeners will be called with the following arguments:

- `el` : Ext.Element
- `oResponseObject` : Object
  The response Object

Updater