Welcome to Ext 2.0. In the following sections, you will learn about all of the major new changes within Ext 2.0. You'll learn, at a high level, what new functionality exists and what you can do with it. However, as an overview, this guide will not discuss many of the details that you'll need as you embark on writing your own Ext 2.0 application. For additional information, here are some helpful resources:
| Summary: An introduction to the major changes between Ext 1.x and 2.0. |
| Author: Brian Moeskau |
| Published: November 15, 2007 |
| Ext Version: 2.0 |
Languages: English Chinese Japanese
|
Contents |
Here's a high-level summary of what's new in 2.0. There have been countless minor improvements, bug fixes and other changes across the framework from 1.x to 2.0. It would be impossible to list everything, so this overview is focused on the major areas where either the architecture has shifted, or there is some entirely new area of functionality. Each item is explained in detail in the sections following this summary.
One of the goals with 2.0 was to provide more basic building blocks. The Component class was originally introduced in 1.x, but was not fully integrated throughout the framework. In 2.0, Component's capabilities have been further expanded and improved upon, making it one of the most fundamental classes in the overall architecture. Component now provides a unified model for component creation, rendering, event handling, state management and destruction, and every component in Ext that requires these features now extends Component. Here are the key features of Component in 2.0:
In general, the Component architecture in 2.0 will "just work." It's been designed to handle most of the management of components transparently to the end developer. However, there will come a time when something needs to be customized, or a Component needs to be extended. That's when a thorough understanding of the Component life cycle will become quite helpful. Following are the most important stages in the life cycle of every class based on Component:
A new concept in 2.0 is that of xtypes, or Ext-specific component types. The available xtypes are summarized in the header of the Component class API. XTypes can be used similarly to regular JavaScript object types to look up or compare Components by type using methods like isXType and getXType. You can also list the xtype hierarchy of any Component using getXTypes.
However, the real power of XTypes is how they can be used to optimize Component creation and rendering. Any Component can be created implicitly as an object config with an xtype specified, allowing it to be declared and passed into the rendering pipeline without actually being instantiated as an object. Not only is rendering deferred, but the actual creation of the object itself is also deferred, saving memory and resources until they are actually needed. In complex, nested layouts containing many Components, this can make a noticeable improvement in performance.
//Explicit creation of contained Components: var panel = new Ext.Panel({ ... items: [ new Ext.Button({ text: 'OK' }) ] }; //Implicit creation using xtype: var panel = new Ext.Panel({ ... items: [{ xtype: 'button', text: 'OK' }] };
In the first example, the button will always be created immediately during the panel's initialization. With many added Components, this approach could potentially slow the rendering of the page. In the second example, the button will not be created or rendered until the panel is actually displayed in the browser. If the panel is never displayed (for example, if it is a tab that remains hidden) then the button will never be created and will never consume any resources whatsoever.
While not new to 2.0, BoxComponent is another critical foundation class that extends Component and provides a consistent, cross-browser box model implementation for any component that will be visually rendered and can participate in layouts. BoxComponent transparently handles sizing and positioning, automatically dealing with any browser-specific differences in padding, margins and borders to produce a consistent box model across every supported browser. All container classes in 2.0 extend BoxComponent.
Container is the most basic foundation for any component that will contain other components. It provides the layout and rendering logic needed for handling sizing and nesting of other components, and also provides the basic mechanism for consistently adding components to the container. The Container class should never need to be used directly, but is intended as the base class for all visual container components.
Panel is the workhorse container in 2.0, and will be what you use for 90% of your layout tasks. At its most basic, a Panel can be a completely non-visual box used for constructing layouts. However, Panel also provides the basic building blocks needed in an application UI window, including bottom and top bars for adding toolbars and menus, a header, footer and body. It also provides built-in expandable and collapsible behavior and tool buttons, as well as pre-built buttons for a variety of other tools. Panels can be easily dropped into any Container or layout, and the layout and rendering logic are completely managed by Ext.
The following Panel subclasses are primary widgets in Ext 2.0:
Window is a specialized Panel that also can be floated, minimized/maximized, restored, dragged, etc. It is intended as the foundation class for desktop-like windowed application UIs as can be seen in the Ext Desktop Demo.
The Viewport is a utility container class that automatically renders to the document body and sizes itself to the dimensions of the browser viewport. This is a handy shortcut for creating full-screen applications as browser resizing and layout recalculations are managed for you automatically. Note that the Viewport cannot be rendered to any container other than document.body, and as such, you can only use one Viewport instance per page.
One of the most significant areas of improvement in 2.0 is the ease and flexibility with which you can create sophisticated application layouts. In Ext 1.x, layout development was centered around the BorderLayout, Region and ContentPanel classes. While the 1.x BorderLayout made it extremely easy to generate attractive UIs, it did not provide enough building blocks to allow truly custom layout creation. Creating complex layouts often required some manual coding to deal with scroll bars, nesting issues and other quirks.
Ext 2.0 has delivered a completely revamped, enterprise-level layout management system. There are now 10 separate layout managers, providing the foundation for building just about any possible style of application layout. Layouts are also managed by Ext so that size, position, scroll and other attributes simply work as expected, right out of the box. You can mix and match different containers, each with a different layout, nesting to any level you want, and it's a snap.
Layouts are not intended to be created directly via the new keyword. Instead, they are created and used internally by the container classes. Containers themselves know nothing about layout — they simply delegate layout duties to whichever layout class has been specified during their configuration. Anytime you create a container, you can specify its layout style and configure any options that are specific to the layout class via the layoutConfig property. For example:
var panel = new Panel({ title: 'My Accordion', layout: 'accordion', // The layout style to use in this panel layoutConfig: { animate: true // Layout-specific config values go here } // additional Panel options... });
It is also important to understand that when you create nested layouts, with Panels containing other Panels, every Panel in the layout must have a layout specified. In most cases when you don't need a specific layout style like 'border' or 'accordion,' you will probably want to specify 'fit' as it will still manage the base sizing of the Panel for you within its container. If you do not specify a layout, the default ContainerLayout class will take over so that the application will still work. However, in most real world cases, the resulting behavior will not be what is expected without an explicit layout.
Each layout class supports its own specific config options. Be sure to reference the API docs for each layout for more information.
![]() |
ContainerLayoutThis is the base class for all other layout managers, and the default layout for containers when a specific layout is not defined. ContainerLayout has no visual representation — it simply manages contained items, rendering them when needed and handling basic duties like resize buffering. ContainerLayout should not generally be created directly, although it can be extended to create custom layouts. See the API reference. |
![]() |
CardLayoutCardLayout is a specific layout used in cases where a container holds multiple elements, but only a single item can be visible at any given time. Most commonly, this layout style is used for wizards, custom tab implementations, or any other use case requiring multiple, mutually-exclusive pages of information. See the API reference. |
![]() |
AbsoluteLayoutThis is a very simple layout that allows you to position contained items precisely via X/Y coordinates relative to the container. See the API reference. |
![]() |
ColumnLayoutThis is the layout style of choice for creating structural layouts in a multi-column format where the width of each column can be specified as a percentage or pixel width, but the height is allowed to vary based on content. See the API reference. |
![]() |
AccordionLayoutThe AccordionLayout contains a set of vertically-stacked panels that can be expanded and collapsed to display content. Only one panel can be open at a time. See the API reference. |
![]() |
FitLayoutThis is a simple layout style that fits a single contained item to the exact dimensions of the container. This is usually the best default layout to use within containers when no other specific layout style is called for. See the API reference. |
![]() |
AnchorLayoutThis layout is for anchoring elements relative to the sides of the container. The elements can be anchored by percentage or by offsets from the edges, and it also supports a virtual layout canvas that can have different dimensions than the physical container. See the API reference. |
![]() |
FormLayoutThe FormLayout is a utility layout specifically designed for creating data entry forms. Note that, in general, you will likely want to use a FormPanel rather than a regular Panel with layout:'form' since FormPanels also provide automatic form submission handling. FormPanels must use layout:'form' (this cannot be changed), so forms needing additional layout styles should use nested Panels to provide them. See the API reference. |
![]() |
BorderLayoutThis is the exact same layout style as BorderLayout in 1.x — layout regions with built-in support for nesting, sliding panels open and closed and splitters separating regions. This is the most common layout style for the primary UI in typical business applications. See the API reference. |
![]() |
TableLayoutThis layout style generates standard HTML table markup with support for column and row spanning. See the API reference. |
The grid UI is actually implemented by the GridView class, and in 2.0 the GridView has been greatly improved. Major new features in the 2.0 GridView include:
Some may notice that the column locking feature, introduced in Ext 1.x, has been removed in 2.0 and will no longer be supported. Column locking, while useful for a small subset of users, was not compatible with many of the new features implemented in the 2.0 GridView (e.g. grouping, summaries, etc) and led to decreased performance for everyone due to the way the grid had to be rendered in order to support locking. It might be possible to port the 1.x GridView forward to 2.0, or to patch the 2.0 GridView to support it, but this will not be done officially by the Ext team.
Note: There is an effort currently underway in the community to implement column locking via a user extension for 2.0, and it is already looking pretty promising as of this writing. More information is available in the forum thread.
XTemplate provides a variety of built-in tags and special operators to support extremely robust template processing using complex data structures. Here is the high-level list of supported features — for complete details and usage examples, please see the XTemplate API docs.
On the surface, DataView is very similar to the 1.x View class. Both support templated data rendering, both are bound to data stores and both have built-in selection models and events. However, the DataView is a huge step forward as it leverages the full power of the new 2.0 architecture. Here are the most significant changes:
Several interesting new components and widgets have been added in 2.0. Make sure you have a look at their API documentation for complete details on what each component has to offer.
An Action is a piece of reusable functionality that can be abstracted out of any particular component so that it can be usefully shared among multiple components. Actions let you share handlers, configuration options and UI updates across any components that support the Action interface (primarily Toolbar, Button and Menu components). See the API Reference.
This is a specialized SplitButton implementation that contains a menu of CheckItem elements. The button automatically cycles through each menu item on click, raising the button's change event (or calling the button's changeHandler function, if supplied) for the active menu item. An example can be seen in the FeedViewer demo application — the button that sets the preview window location is a CycleButton. API Reference.
This is simply a convenience field that renders as a standard HTML hidden input field. This is quite useful for storing hidden values to submit with the form, and in 2.0 hidden fields can be created and manipulated just like other Ext form components. See the API Reference.
There was a simple progress bar built into the MessageBox class in 1.x. Now it has been factored out into a separate widget and further improved. It supports two different modes (manual and automatic progress) and the look and feel can be easily customized. See the API Reference.
This is a simple time picker dropdown implementation. See the API Reference.