Ext JS - Documentation

Getting Started

Installation and Setup

Ext JS can be integrated into your project via several methods, offering flexibility depending on your workflow and project requirements. The most common approaches include using a CDN, npm, or yarn.

Using a CDN: The quickest way to get started is by including the Ext JS library via a CDN link in your HTML file. This method is ideal for quick prototyping or small projects. Refer to the Sencha website for the most up-to-date CDN links and instructions. Be aware that using a CDN relies on an external resource, so network availability impacts your application’s performance.

Using npm (or yarn): For larger projects, using a package manager like npm (Node Package Manager) or yarn is strongly recommended. This ensures proper version control and dependency management. You’ll need Node.js installed on your system. To install Ext JS, use the following command in your terminal:

npm install sencha-extjs

(or yarn add sencha-extjs for yarn). After installation, you’ll need to configure your build process (e.g., using Webpack or a similar tool) to incorporate Ext JS into your application. Refer to the Sencha documentation for detailed instructions on building and optimizing your Ext JS application using npm.

Creating Your First Ext JS Application

The simplest Ext JS application consists of a single Ext.Application instance and a minimal view. Let’s create a basic “Hello, World!” application:

Ext.application({
    name: 'MyApp',
    launch: function() {
        Ext.create('Ext.panel.Panel', {
            renderTo: Ext.getBody(),
            width: 300,
            height: 200,
            title: 'My First Ext JS App',
            html: 'Hello, World!'
        });
    }
});

This code creates a simple panel displaying “Hello, World!”. Ext.application creates the application instance. The launch function is called when the application is ready. Ext.create instantiates a panel, which is rendered to the document body (Ext.getBody()). This code snippet requires the inclusion of the Ext JS library (either via CDN or via your chosen package manager). Save this code as an HTML file (e.g., index.html), ensure the Ext JS library is properly included, and open the file in a web browser to see the result.

Understanding the MVC Architecture

Ext JS employs a Model-View-Controller (MVC) architecture to structure applications. This pattern promotes code organization, reusability, and maintainability.

Ext JS provides classes and utilities to implement the MVC pattern effectively, facilitating the creation of well-structured and scalable applications. Understanding this architecture is crucial for effectively using Ext JS.

Exploring the Ext JS Class System

Ext JS utilizes a powerful and flexible class system based on inheritance and prototypes. This system is fundamental to extending existing components and creating custom ones. Key concepts include:

Mastering the Ext JS class system is essential for developing complex and customized applications. The documentation provides detailed examples and explanations of these concepts. Experiment with creating simple custom classes to solidify your understanding.

Core Components

Panels and Containers

Panels and containers are fundamental building blocks in Ext JS, providing the structure for your application’s layout. Panels are rectangular components that can contain other components. Containers manage the layout and arrangement of child components within them. Key container classes include:

Understanding the different container layouts and how to nest them is crucial for creating effective user interfaces.

Forms and Fields

Ext JS provides a comprehensive set of form components for creating data entry interfaces. Forms are built using field components, each representing a single input element. Key features include:

Grids and Data Management

Grids are essential for displaying tabular data. Ext JS’s grid component (Ext.grid.Grid) is highly flexible and powerful, offering features like sorting, filtering, paging, and editing. Key aspects include:

Windows and Dialogs

Windows and dialogs are used to display modal or modeless pop-up windows. They’re crucial for creating interactive user experiences. Key components include:

Menus and toolbars enhance user interaction by providing easy access to commands and options.

Buttons and Icons

Buttons are fundamental interactive components that trigger actions. Ext JS provides various button types and options for customization.

Data Handling

Data Models and Stores

Ext JS uses a robust data handling system centered around Models and Stores. Models represent individual data records, while Stores manage collections of Models and provide interfaces for data manipulation and access.

Working with AJAX and Proxies

Proxies act as intermediaries between Stores and data sources, typically handling asynchronous communication via AJAX. They abstract the details of data fetching and saving.

Data Binding and Templating

Ext JS simplifies data binding, enabling components to automatically update when underlying data changes and vice-versa. Templating allows for customized data rendering within components.

Data Validation and Error Handling

Ext JS supports data validation at both the Model and form levels. Error handling mechanisms provide ways to gracefully handle validation failures and data loading errors.

Server-Side Data Integration

Ext JS integrates seamlessly with various server-side technologies. The choice of technology depends on your project requirements. Common approaches include:

UI Components

Buttons

Buttons provide a fundamental way for users to interact with your application. Ext JS offers a flexible Ext.button.Button class with numerous configuration options.

Text Fields

Text fields (Ext.form.field.Text) allow users to input and edit text.

Number Fields

Number fields (Ext.form.field.Number) are specifically designed for numerical input.

Date Fields

Date fields (Ext.form.field.Date) handle date input.

Checkboxes and Radio Buttons

Checkboxes (Ext.form.field.Checkbox) and radio buttons (Ext.form.field.Radio) allow users to select one or multiple options.

Combo Boxes and Dropdowns

Combo boxes (Ext.form.field.ComboBox) and dropdowns provide a list of options for selection.

List Views and Data Grids

List views (Ext.view.View) display lists of items; data grids (Ext.grid.Grid) are specifically designed for tabular data.

Trees and Tree Grids

Trees (Ext.tree.Panel) and tree grids (Ext.tree.Panel with grid features) display hierarchical data.

Tabs

Tabs (Ext.tab.Panel) allow organizing content into multiple tabbed panels.

Accordions

Accordions (Ext.panel.Accordion) display panels in an expandable/collapsible format.

Progress Bars and Load Masks

Progress bars (Ext.ProgressBar) and load masks (Ext.LoadMask) indicate ongoing operations.

Charts

Ext JS provides integration with various charting libraries to render various types of charts.

Custom Components

Ext JS’s class system allows for creating custom components by extending existing ones or building them from scratch.

Component Layouts

Layouts control how components are arranged within containers. Ext JS offers various layouts:

Advanced Topics

Extending Ext JS Classes

Ext JS’s class system allows extending existing classes to add functionality or modify behavior. This is achieved using Ext.define() and specifying the parent class.

Ext.define('MyApp.MyCustomButton', {
    extend: 'Ext.button.Button',
    config: {
        customProperty: 'defaultValue'
    },
    onClick: function() {
        // Custom click handling logic
        console.log('Custom button clicked!');
        this.callParent(arguments); // Call the parent class's onClick method
    }
});

This example extends Ext.button.Button, adding a custom property and overriding the onClick method. callParent ensures that the original functionality is also executed.

Creating Custom Components

Building entirely new components involves defining classes using Ext.define(), specifying the component’s properties, methods, and render logic. Consider using existing components as a starting point for inheritance.

Ext.define('MyApp.MyCustomComponent', {
    extend: 'Ext.Component',
    renderTpl: [
        '<div class="my-custom-component">',
        '<tpl if="title">',
        '<h1>{title}</h1>',
        '</tpl>',
        '<p>{text}</p>',
        '</div>'
    ],
    config: {
        title: null,
        text: null
    },
    applyText: function(text) {
       return text || "Default Text";
    }
});

This creates a simple component rendering a title and text. renderTpl defines the HTML template, and config specifies configurable properties.

Working with Events and Listeners

Ext JS uses an event-driven architecture. Components emit events, and you can add listeners to respond to these events.

const myButton = Ext.create('Ext.button.Button', {
    text: 'Click Me',
    listeners: {
        click: function() {
            console.log('Button clicked!');
        }
    }
});

// Alternatively using on():
myButton.on('click', function() {
    console.log('Button clicked using on()!');
});

These examples demonstrate attaching a click listener to a button. listeners is a config option; on() adds listeners dynamically.

Internationalization and Localization

Ext JS supports internationalization (i18n) and localization (l10n) for creating multilingual applications. This usually involves using JSON files for storing translated text and loading the appropriate translations based on the user’s locale.

Performance Optimization

Optimizing Ext JS applications focuses on minimizing render time, efficient data handling, and avoiding unnecessary DOM manipulations.

Debugging and Troubleshooting

Debugging Ext JS applications involves using browser developer tools (e.g., Chrome DevTools) to inspect component state, network requests, and JavaScript errors. Ext JS’s logging mechanisms can be valuable for tracking application behavior.

Testing and Unit Testing

Thorough testing is essential for building robust applications. Ext JS applications can be tested using various methods, including unit testing frameworks like Jasmine or Jest.

Deployment and Distribution

Deploying Ext JS applications involves building optimized code, serving the application, and managing dependencies.

Ext JS Modern Toolkit

Overview of Modern Toolkit

The Ext JS Modern toolkit is a framework for building modern, touch-friendly web applications. It leverages the power of HTML5, CSS3, and JavaScript to create responsive and performant user interfaces that work seamlessly across a wide range of devices, including desktops, tablets, and smartphones. It uses a completely different rendering engine and component architecture compared to the Classic toolkit. The Modern toolkit is designed with mobile-first principles in mind and offers a sleek, modern look and feel out of the box. It prioritizes touch interactions and adapts easily to various screen sizes.

Key Differences from Classic Toolkit

The Modern and Classic toolkits are distinct and not directly compatible. Key differences include:

Migrating from Classic to Modern often requires substantial refactoring and rewriting of code, as they are fundamentally different frameworks.

Component-Specific Details

Many components in the Modern toolkit mirror those in the Classic toolkit, but with different APIs and behaviors. You will need to refer to the Modern toolkit documentation for detailed information about specific components. Key considerations include:

Modern Toolkit Examples

A simple “Hello, World!” example using the Modern toolkit:

Ext.application({
    name: 'MyApp',
    launch: function() {
        Ext.create('Ext.Container', {
            fullscreen: true,
            items: [{
                xtype: 'panel',
                html: 'Hello, World!'
            }]
        });
    }
});

This code creates a simple panel displaying “Hello, World!” that fills the entire screen. Note the use of fullscreen: true and xtype for component creation. Explore the extensive examples provided in the official Sencha documentation to see how various Modern components are used to create more complex applications. The documentation will also cover the various layout options available and how to integrate data handling with modern components like grids and lists.

Ext JS Classic Toolkit

Overview of Classic Toolkit

The Ext JS Classic toolkit is a mature and feature-rich framework for building web applications. While the Modern toolkit is now the recommended approach for new projects, Classic remains a powerful option for maintaining and extending existing applications. It employs a different rendering mechanism than the Modern toolkit, relying heavily on DOM manipulation. While still functional, it generally lags behind Modern in terms of performance, especially on mobile devices. The Classic toolkit’s architecture is largely based on the MVC (Model-View-Controller) pattern and offers a wide range of components and utilities for building complex web applications. However, its design might appear less modern compared to the streamlined approach of the Modern toolkit.

Component-Specific Details

Many components in the Classic toolkit have counterparts in the Modern toolkit, but their APIs and behaviors can differ significantly. Detailed information about specific components is available in the Ext JS Classic toolkit documentation. Key differences to note from the Modern toolkit include:

Classic Toolkit Examples

A simple “Hello, World!” example using the Classic toolkit:

Ext.onReady(function() {
    Ext.create('Ext.Panel', {
        renderTo: Ext.getBody(),
        width: 300,
        height: 200,
        title: 'My First Ext JS App',
        html: 'Hello, World!'
    });
});

This code creates a simple panel, renders it to the document body, and displays “Hello, World!”. Ext.onReady ensures the code runs after the DOM is fully loaded. The renderTo config option specifies the target element. Note that creating more complex applications will require a more robust architecture using Models, Views, and Controllers. The Classic toolkit documentation provides extensive examples that showcase various components and their interactions, including forms, grids, and advanced layouts. These examples should be consulted to learn more about the intricate details of building applications with the Classic toolkit.

API Reference

The Ext JS API is extensive and well-documented. This section provides an overview of the key parts of the API reference. For the most up-to-date and comprehensive information, always consult the official Sencha Ext JS API documentation.

Class Reference

The class reference provides detailed information on all the classes available in Ext JS. For each class, the documentation typically includes:

You can typically access the class reference through the official documentation website by searching for the class name or browsing the class hierarchy.

Method Reference

The method reference details the available methods for each class. For each method, you’ll typically find:

The method reference is typically integrated into the class reference, listed under the “Methods” section for each class.

Config Options Reference

Config options allow you to customize the behavior and appearance of Ext JS components. The config options reference provides detailed information on these options. Each config option description typically includes:

Config options are usually documented within the class reference, often in a dedicated section or table.

Events Reference

The events reference lists the events fired by each class. This is crucial for understanding how to respond to changes in component state or user interactions. For each event, the documentation provides:

Similar to methods and config options, the events reference is typically found within the class reference, under a dedicated “Events” section. Understanding the events fired by components allows you to build dynamic and responsive applications. You can use the addListener method (or its shorthand on) to attach event handlers.