Properties Methods Events Config Options Direct Link

    Observable
      Component

# Class Ext.Component

Package: | Ext
Defined In: | Component.js
Class: | Component
Subclasses: | BoxComponent, Button, ColorPalette, DatePicker, Editor, BaseItem
Extends: | Observable

Base class for all Ext components. All subclasses of Component can automatically participate in the standard Ext component lifecycle of creation, rendering and destruction. They also have automatic support for basic hide/show and enable/disable behavior. Component allows any subclass to be lazy-rendered into any Ext.Container and to be automatically registered with the Ext.ComponentMgr so that it can be referenced at any time via Ext.getCmp. All visual widgets that require rendering into a layout should subclass Component (or Ext.BoxComponent if managed box model handling is required).

Every component has a specific xtype, which is its Ext-specific type name, along with methods for checking the xtype like getXType and isXType. This is the list of all valid xtypes:

    xtype            Class
    -------------    ------------------
    box              Ext.BoxComponent
    button           Ext.Button
    colorpalette     Ext.ColorPalette
    component        Ext.Component
    container        Ext.Container
    cycle            Ext.CycleButton
    dataview         Ext.DataView
    datepicker       Ext.DatePicker
    editor           Ext.Editor
    editorgrid       Ext.grid.EditorGridPanel
    grid             Ext.grid.GridPanel
    paging           Ext.PagingToolbar
    panel            Ext.Panel
    progress         Ext.ProgressBar
    splitbutton      Ext.SplitButton
    tabpanel         Ext.TabPanel
    treepanel        Ext.tree.TreePanel
    viewport         Ext.ViewPort
    window           Ext.Window

    Toolbar components
    ---------------------------------------
    toolbar          Ext.Toolbar
    tbbutton         Ext.Toolbar.Button
    tbfill           Ext.Toolbar.Fill
    tbitem           Ext.Toolbar.Item
    tbseparator      Ext.Toolbar.Separator
    tbspacer         Ext.Toolbar.Spacer
    tbsplit          Ext.Toolbar.SplitButton
    tbtext           Ext.Toolbar.TextItem

    Form components
    ---------------------------------------
    form             Ext.FormPanel
    checkbox         Ext.form.Checkbox
    combo            Ext.form.ComboBox
    datefield        Ext.form.DateField
    field            Ext.form.Field
    fieldset         Ext.form.FieldSet
    hidden           Ext.form.Hidden
    htmleditor       Ext.form.HtmlEditor
    numberfield      Ext.form.NumberField
    radio            Ext.form.Radio
    textarea         Ext.form.TextArea
    textfield        Ext.form.TextField
    timefield        Ext.form.TimeField
    trigger          Ext.form.TriggerField

## Config Options

Config Options | Defined By
--- | ---
| allowDomMove : Boolean Whether the component can move the Dom node when rendering (defaults to true). | Component
| applyTo : Mixed The id of the node, a DOM node or an existing Element corresponding to a DIV that is already present in the document ... The id of the node, a DOM node or an existing Element corresponding to a DIV that is already present in the document that specifies some structural markup for this component. When applyTo is used, constituent parts of the component can also be specified by id or CSS class name within the main element, and the component being created may attempt to create its subcomponents from that markup if applicable. Using this config, a call to render() is not required. If applyTo is specified, any value passed for renderTo will be ignored and the target element's parent node will automatically be used as the component's container. | Component
| autoEl : String/Object A tag name or DomHelper spec to create an element with. This is intended to create shorthand utility components inlin... A tag name or DomHelper spec to create an element with. This is intended to create shorthand utility components inline via JSON. It should not be used for higher level components which already create their own elements. Example usage:
    {xtype:'box', autoEl: 'div', cls:'my-class'}
    {xtype:'box', autoEl: {tag:'blockquote', html:'autoEl is cool!'}} // with DomHelper
| Component
| autoShow : Boolean True if the component should check for hidden classes (e.g. 'x-hidden' or 'x-hide-display') and remove them on render... True if the component should check for hidden classes (e.g. 'x-hidden' or 'x-hide-display') and remove them on render (defaults to false). | Component
| cls : String An optional extra CSS class that will be added to this component's Element (defaults to ''). This can be useful for a... An optional extra CSS class that will be added to this component's Element (defaults to ''). This can be useful for adding customized styles to the component or any of its children using standard CSS rules. | Component
| ctCls : String An optional extra CSS class that will be added to this component's container (defaults to ''). This can be useful for... An optional extra CSS class that will be added to this component's container (defaults to ''). This can be useful for adding customized styles to the container or any of its children using standard CSS rules. | Component
| disabledClass : String CSS class added to the component when it is disabled (defaults to "x-item-disabled"). | Component
| hideMode : String How this component should hidden. Supported values are "visibility" (css visibility), "offsets" (negative offset posi... How this component should hidden. Supported values are "visibility" (css visibility), "offsets" (negative offset position) and "display" (css display) - defaults to "display". | Component
| hideParent : Boolean True to hide and show the component's container when hide/show is called on the component, false to hide and show the... True to hide and show the component's container when hide/show is called on the component, false to hide and show the component itself (defaults to false). For example, this can be used as a shortcut for a hide button on a window by setting hide:true on the button when adding it to its parent container. | Component
| id : String The unique id of this component (defaults to an auto-assigned id). | Component
| listeners : Object A config object containing one or more event handlers to be added to this object during initialization. This should b... 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. | Observable
| plugins : Object/Array An object or array of objects that will provide custom functionality for this component. The only requirement for a v... 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. | Component
| renderTo : Mixed The id of the node, a DOM node or an existing Element that will be the container to render this component into. Using... The id of the node, a DOM node or an existing Element that will be the container to render this component into. Using this config, a call to render() is not required. | Component
| stateEvents : Array An array of events that, when fired, should trigger this component to save its state (defaults to none). These can be... An array of events that, when fired, should trigger this component to save its state (defaults to none). These can be any types of events supported by this component, including browser or custom events (e.g., ['click', 'customerchange']). See stateful for an explanation of saving and restoring Component state. | Component
| stateId : String The unique id for this component to use for state management purposes (defaults to the component id). See stateful fo... The unique id for this component to use for state management purposes (defaults to the component id). See stateful for an explanation of saving and restoring Component state. | Component
| stateful : Boolean A flag which causes the Component to attempt to restore the state of internal properties from a saved state on startu... A flag which causes the Component to attempt to restore the state of internal properties from a saved state on startup. For state saving to work, the state manager's provider must have been set to an implementation of Ext.state.Provider which overrides the set and get methods to save and recall name/value pairs. A built-in implementation, Ext.state.CookieProvider is available. To set the state provider for the current page:
    Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
Components attempt to save state when one of the events listed in the stateEvents configuration fires. You can perform extra processing on state save and restore by attaching handlers to the beforestaterestore, staterestore, beforestatesave and statesave events | Component
| style : String A custom style specification to be applied to this component's Element. Should be a valid argument to Ext.Element.app... A custom style specification to be applied to this component's Element. Should be a valid argument to Ext.Element.applyStyles. | Component
| xtype : String The registered xtype to create. This config option is not used when passing a config object into a constructor. This ... The registered xtype to create. This config option is not used when passing a config object into a constructor. This config option is used only when lazy instantiation is being used, and a child item of a Container is being specified not as a fully instantiated Component, but as a Component config object. The xtype will be looked up at render time up to determine what type of child Component to create. The predefined xtypes are listed here. If you subclass Components to create your own Components, you may register them using Ext.ComponentMgr.registerType in order to be able to take advantage of lazy instantiation and rendering. | Component

## Public Properties

Property | Defined By
--- | ---
| disabled : Boolean True if this component is disabled. Read-only. | Component
| hidden : Boolean True if this component is hidden. Read-only. | Component
| initialConfig : Object This Component's initial configuration specification. Read-only. | Component
| ownerCt : Ext.Container The component's owner Ext.Container (defaults to undefined, and is set automatically when the component is added to a... The component's owner Ext.Container (defaults to undefined, and is set automatically when the component is added to a container). Read-only. | Component
| rendered : Boolean True if this component has been rendered. Read-only. | Component

## Public Methods

Method | Defined By
--- | ---
| Component( `Ext.Element/String/Object config` ) Parameters: `config` : Ext.Element/String/Object The configuration options. If an element is passed, it is set as the internal element and its id used as the component id. If a string is passed, it is assumed to be the id of an existing element and is used as the component id. Otherwise, it is assumed to be a standard config object and is applied to the component. Returns: `` | Component
| addClass( `string cls` ) : void Adds a CSS class to the component's underlying element. Adds a CSS class to the component's underlying element. Parameters: `cls` : string The CSS class name to add Returns: `void` | Component
| addEvents( `Object object` ) : void Used to define events on this Observable Used to define events on this Observable Parameters: `object` : Object The object with the events defined Returns: `void` | Observable
- | addListener( `String eventName`, `Function handler`, [`Object scope`], [`Object options`] ) : void Appends an event handler to this component Appends an event handler to this component Parameters: `eventName` : String The type of event to listen for `handler` : Function The method the event invokes `scope` : Object (optional) The scope in which to execute the handler function. The handler function's "this" context. `options` : Object (optional) An object containing handler configuration properties. This may contain any of the following properties: scope : Object The scope in which to execute the handler function. The handler function's "this" context. 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. Combining Options Using the options argument, it is possible to combine different types of listeners: A normalized, delayed, one-time listener that auto stops the event and passes a custom argument (forumId)
      el.on('click', this.onClick, this, {
          single: true,
          delay: 100,
          forumId: 4
      });
  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.
      foo.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:
      foo.on({
          'click' : this.onClick,
          'mouseover' : this.onMouseOver,
          'mouseout' : this.onMouseOut,
           scope: this
      });
Returns: `void` | Observable
| applyToMarkup( `String/HTMLElement el` ) : void Apply this component to existing markup that is valid. With this function, no call to render() is required. Apply this component to existing markup that is valid. With this function, no call to render() is required. Parameters: `el` : String/HTMLElement Returns: `void` | Component
| cloneConfig( `Object overrides` ) : Ext.Component Clone the current component using the original config values passed into this instance by default. Clone the current component using the original config values passed into this instance by default. Parameters: `overrides` : Object A new config containing any properties to override in the cloned version. An id property can be passed on this object, otherwise one will be generated to avoid duplicates. Returns: `Ext.Component` clone The cloned copy of this component | Component
| destroy() : void Destroys this component by purging any event listeners, removing the component's element from the DOM, removing the c... Destroys this component by purging any event listeners, removing the component's element from the DOM, removing the component from its Ext.Container (if applicable) and unregistering it from Ext.ComponentMgr. Destruction is generally handled automatically by the framework and this method should usually not need to be called directly. Parameters: None. Returns: `void` | Component
| disable() : Ext.Component Disable this component. Disable this component. Parameters: None. Returns: `Ext.Component` this | Component
| enable() : Ext.Component Enable this component. Enable this component. Parameters: None. Returns: `Ext.Component` this | Component
| findParentBy( `Function fcn`, [`Object scope`] ) : Array Find a container above this component at any level by a custom function. If the passed function returns true, the con... Find a container above this component at any level by a custom function. If the passed function returns true, the container will be returned. The passed function is called with the arguments (container, this component). Parameters: `fcn` : Function `scope` : Object (optional) Returns: `Array` Array of Ext.Components | Component
| findParentByType( `String/Class xtype` ) : Container Find a container above this component at any level by xtype or class Find a container above this component at any level by xtype or class Parameters: `xtype` : String/Class The xtype string for a component, or the class of the component directly Returns: `Container` The found container | Component
| fireEvent( `String eventName`, `Object... 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). Parameters: `eventName` : String `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
| focus( [`Boolean selectText`], [`Boolean/Number delay`] ) : Ext.Component Try to focus this component. Try to focus this component. Parameters: `selectText` : Boolean (optional) If applicable, true to also select the text in this component `delay` : Boolean/Number (optional) Delay the focus this number of milliseconds (true for 10 milliseconds) Returns: `Ext.Component` this | Component
| getEl() : Ext.Element Returns the underlying Ext.Element. Returns the underlying Ext.Element. Parameters: None. Returns: `Ext.Element` The element | Component
| getId() : String Returns the id of this component. Returns the id of this component. Parameters: None. Returns: `String` | Component
| getItemId() : String Returns the item id of this component. Returns the item id of this component. Parameters: None. Returns: `String` | Component
| getXType() : String Gets the xtype for this component as registered with Ext.ComponentMgr. For a list of all available xtypes, see the Ex... Gets the xtype for this component as registered with Ext.ComponentMgr. For a list of all available xtypes, see the Ext.Component header. Example usage:
    var t = new Ext.form.TextField();
    alert(t.getXType());  // alerts 'textfield'
Parameters: None. Returns: `String` The xtype | Component
| getXTypes() : String Returns this component's xtype hierarchy as a slash-delimited string. For a list of all available xtypes, see the Ext... Returns this component's xtype hierarchy as a slash-delimited string. For a list of all available xtypes, see the Ext.Component header. Example usage:
    var t = new Ext.form.TextField();
    alert(t.getXTypes());  // alerts 'component/box/field/textfield'
Parameters: None. Returns: `String` The xtype hierarchy string | Component
| 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
| hide() : Ext.Component Hide this component. Hide this component. Parameters: None. Returns: `Ext.Component` this | Component
| isVisible() : void Returns true if this component is visible. Returns true if this component is visible. Parameters: None. Returns: `void` | Component
| isXType( `String xtype`, [`Boolean shallow`] ) : void Tests whether or not this component is of a specific xtype. This can test whether this component is descended from th... Tests whether or not this component is of a specific xtype. This can test whether this component is descended from the xtype (default) or whether it is directly of the xtype specified (shallow = true). For a list of all available xtypes, see the Ext.Component header. Example usage:
    var t = new Ext.form.TextField();
    var isText = t.isXType('textfield');        // true
    var isBoxSubclass = t.isXType('box');       // true, descended from BoxComponent
    var isBoxInstance = t.isXType('box', true); // false, not a direct BoxComponent instance
Parameters: `xtype` : String The xtype to check for this component `shallow` : Boolean (optional) False to check whether this component is descended from the xtype (this is the default), or true to check whether this component is directly of the specified xtype. Returns: `void` | Component
| on( `String eventName`, `Function handler`, [`Object scope`], [`Object options`] ) : void Appends an event handler to this element (shorthand for addListener) Appends an event handler to this element (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 in which to execute the handler function. The handler function's "this" context. `options` : Object (optional) Returns: `void` | Observable
| purgeListeners() : void Removes all listeners for this object Removes all listeners for this object Parameters: None. Returns: `void` | Observable
| removeClass( `string cls` ) : void Removes a CSS class from the component's underlying element. Removes a CSS class from the component's underlying element. Parameters: `cls` : string The CSS class name to remove Returns: `void` | Component
| removeListener( `String eventName`, `Function handler`, [`Object scope`] ) : void Removes a listener Removes a listener Parameters: `eventName` : String The type of event to listen for `handler` : Function The handler to remove `scope` : Object (optional) The scope (this object) for the handler Returns: `void` | Observable
| render( [`Mixed container`], [`String/Number position`] ) : void If this is a lazy rendering component, render it to its container element. If this is a lazy rendering component, render it to its container element. Parameters: `container` : Mixed (optional) The element this component should be rendered into. If it is being applied to existing markup, this should be left off. `position` : String/Number (optional) The element ID or DOM node index within the container before which this component will be inserted (defaults to appending to the end of the container) Returns: `void` | Component
| resumeEvents() : void Resume firing events. (see suspendEvents) Resume firing events. (see suspendEvents) Parameters: None. Returns: `void` | Observable
| setDisabled( `Boolean disabled` ) : void Convenience function for setting disabled/enabled by boolean. Convenience function for setting disabled/enabled by boolean. Parameters: `disabled` : Boolean Returns: `void` | Component
| setVisible( `Boolean visible` ) : Ext.Component Convenience function to hide or show this component by boolean. Convenience function to hide or show this component by boolean. Parameters: `visible` : Boolean True to show, false to hide Returns: `Ext.Component` this | Component
| show() : Ext.Component Show this component. Show this component. Parameters: None. Returns: `Ext.Component` this | Component
| suspendEvents() : void Suspend the firing of all events. (see resumeEvents) Suspend the firing of all events. (see resumeEvents) Parameters: None. Returns: `void` | Observable
| un( `String eventName`, `Function handler`, [`Object scope`] ) : void Removes a listener (shorthand for removeListener) Removes a listener (shorthand for removeListener) Parameters: `eventName` : String The type of event to listen for `handler` : Function The handler to remove `scope` : Object (optional) The scope (this object) for the handler Returns: `void` | Observable

## Public Events

Event | Defined By
--- | ---
| beforedestroy : ( `Ext.Component this` ) Fires before the component is destroyed. Return false to stop the destroy. Fires before the component is destroyed. Return false to stop the destroy. Listeners will be called with the following arguments: `this` : Ext.Component | Component
| beforehide : ( `Ext.Component this` ) Fires before the component is hidden. Return false to stop the hide. Fires before the component is hidden. Return false to stop the hide. Listeners will be called with the following arguments: `this` : Ext.Component | Component
| beforerender : ( `Ext.Component this` ) Fires before the component is rendered. Return false to stop the render. Fires before the component is rendered. Return false to stop the render. Listeners will be called with the following arguments: `this` : Ext.Component | Component
| beforeshow : ( `Ext.Component this` ) Fires before the component is shown. Return false to stop the show. Fires before the component is shown. Return false to stop the show. Listeners will be called with the following arguments: `this` : Ext.Component | Component
| beforestaterestore : ( `Ext.Component this`, `Object state` ) Fires before the state of the component is restored. Return false to stop the restore. Fires before the state of the component is restored. Return false to stop the restore. Listeners will be called with the following arguments: `this` : Ext.Component `state` : Object The hash of state values | Component
| beforestatesave : ( `Ext.Component this`, `Object state` ) Fires before the state of the component is saved to the configured state provider. Return false to stop the save. Fires before the state of the component is saved to the configured state provider. Return false to stop the save. Listeners will be called with the following arguments: `this` : Ext.Component `state` : Object The hash of state values | Component
| destroy : ( `Ext.Component this` ) Fires after the component is destroyed. Fires after the component is destroyed. Listeners will be called with the following arguments: `this` : Ext.Component | Component
| disable : ( `Ext.Component this` ) Fires after the component is disabled. Fires after the component is disabled. Listeners will be called with the following arguments: `this` : Ext.Component | Component
| enable : ( `Ext.Component this` ) Fires after the component is enabled. Fires after the component is enabled. Listeners will be called with the following arguments: `this` : Ext.Component | Component
| hide : ( `Ext.Component this` ) Fires after the component is hidden. Fires after the component is hidden. Listeners will be called with the following arguments: `this` : Ext.Component | Component
| render : ( `Ext.Component this` ) Fires after the component is rendered. Fires after the component is rendered. Listeners will be called with the following arguments: `this` : Ext.Component | Component
| show : ( `Ext.Component this` ) Fires after the component is shown. Fires after the component is shown. Listeners will be called with the following arguments: `this` : Ext.Component | Component
| staterestore : ( `Ext.Component this`, `Object state` ) Fires after the state of the component is restored. Fires after the state of the component is restored. Listeners will be called with the following arguments: `this` : Ext.Component `state` : Object The hash of state values | Component
| statesave : ( `Ext.Component this`, `Object state` ) Fires after the state of the component is saved to the configured state provider. Fires after the state of the component is saved to the configured state provider. Listeners will be called with the following arguments: `this` : Ext.Component `state` : Object The hash of state values | Component