Docs Help

Terms, Icons, and Labels

Many classes have shortcut names used when creating (instantiating) a class with a configuration object. The shortcut name is referred to as an alias (or xtype if the class extends Ext.Component). The alias/xtype is listed next to the class name of applicable classes for quick reference.

Access Levels

Framework classes or their members may be specified as private or protected. Else, the class / member is public. Public, protected, and private are access descriptors used to convey how and when the class or class member should be used.

Member Types

Member Syntax

Below is an example class member that we can disect to show the syntax of a class member (the lookupComponent method as viewed from the Ext.button.Button class in this case).

lookupComponent ( item ) : Ext.Component
protected

Called when a raw config object is added to this container either during initialization of the items config, or when new items are added), or {@link #insert inserted.

This method converts the passed object into an instanced child component.

This may be overridden in subclasses when special processing needs to be applied to child creation.

Parameters

item :  Object

The config object being added.

Returns
Ext.Component

The component to be added.

Let's look at each part of the member row:

Member Flags

The API documentation uses a number of flags to further commnicate the class member's function and intent. The label may be represented by a text label, an abbreviation, or an icon.

Class Icons

- Indicates a framework class

- A singleton framework class. *See the singleton flag for more information

- A component-type framework class (any class within the Ext JS framework that extends Ext.Component)

- Indicates that the class, member, or guide is new in the currently viewed version

Member Icons

- Indicates a class member of type config

- Indicates a class member of type property

- Indicates a class member of type method

- Indicates a class member of type event

- Indicates a class member of type theme variable

- Indicates a class member of type theme mixin

- Indicates that the class, member, or guide is new in the currently viewed version

Class Member Quick-Nav Menu

Just below the class name on an API doc page is a row of buttons corresponding to the types of members owned by the current class. Each button shows a count of members by type (this count is updated as filters are applied). Clicking the button will navigate you to that member section. Hovering over the member-type button will reveal a popup menu of all members of that type for quick navigation.

Getter and Setter Methods

Getting and setter methods that correlate to a class config option will show up in the methods section as well as in the configs section of both the API doc and the member-type menus just beneath the config they work with. The getter and setter method documentation will be found in the config row for easy reference.

History Bar

Your page history is kept in localstorage and displayed (using the available real estate) just below the top title bar. By default, the only search results shown are the pages matching the product / version you're currently viewing. You can expand what is displayed by clicking on the button on the right-hand side of the history bar and choosing the "All" radio option. This will show all recent pages in the history bar for all products / versions.

Within the history config menu you will also see a listing of your recent page visits. The results are filtered by the "Current Product / Version" and "All" radio options. Clicking on the button will clear the history bar as well as the history kept in local storage.

If "All" is selected in the history config menu the checkbox option for "Show product details in the history bar" will be enabled. When checked, the product/version for each historic page will show alongside the page name in the history bar. Hovering the cursor over the page names in the history bar will also show the product/version as a tooltip.

Search and Filters

Both API docs and guides can be searched for using the search field at the top of the page.

On API doc pages there is also a filter input field that filters the member rows using the filter string. In addition to filtering by string you can filter the class members by access level, inheritance, and read only. This is done using the checkboxes at the top of the page.

The checkbox at the bottom of the API class navigation tree filters the class list to include or exclude private classes.

Clicking on an empty search field will show your last 10 searches for quick navigation.

API Doc Class Metadata

Each API doc page (with the exception of Javascript primitives pages) has a menu view of metadata relating to that class. This metadata view will have one or more of the following:

Expanding and Collapsing Examples and Class Members

Runnable examples (Fiddles) are expanded on a page by default. You can collapse and expand example code blocks individually using the arrow on the top-left of the code block. You can also toggle the collapse state of all examples using the toggle button on the top-right of the page. The toggle-all state will be remembered between page loads.

Class members are collapsed on a page by default. You can expand and collapse members using the arrow icon on the left of the member row or globally using the expand / collapse all toggle button top-right.

Desktop -vs- Mobile View

Viewing the docs on narrower screens or browsers will result in a view optimized for a smaller form factor. The primary differences between the desktop and "mobile" view are:

Viewing the Class Source

The class source can be viewed by clicking on the class name at the top of an API doc page. The source for class members can be viewed by clicking on the "view source" link on the right-hand side of the member row.

Ext JS 7.0.0


top

Modern Drag and Drop

Introduction

Ext JS 6.2 introduced the Ext.drag API to provide a cross-toolkit solution to drag-and-drop for the Calendar package. This API provides a collection of classes that allow applications to easily add custom Drag/Drop functionality ranging from basic element manipulation to complex, aysnchronous data transfer. The Ext.drag API is modeled after and greatly expands on the HTML5 drag/drop API and is available for both Classic and Modern Toolkits.

Overview

Ext.drag keeps the element-level API simple with the appropriate hooks to combine with your components. It also allows data related actions to occur asynchronously.

Ext.drag is composed of two main classes: Ext.drag.Source and Ext.drag.Target. A source is something that can be dragged. A target is something that can receive a drop from a source. Both of these classes are attached to an Ext.dom.Element.

This namespace also includes functionality that handles element-level interactions. For components, it is often useful to wrap these classes to provide a more component friendly interface.

Ext.drag.Source

A drag source represents a movable element that can be dragged on screen. Below are some of the main features:

Constraining

Constraints limit the possible positions a drag can occur. Constraints for sources are handled by the Ext.drag.Constraint class. A configuration for this (along with some shortcuts) can be passed to the drag source. Some of the useful options include:

  • Limiting the drag to be only horizontal or vertical

  • Limiting the drag to a particular onscreen region (Ext.util.Region)

  • Limiting the drag to a parent element

  • Limiting the position of the drag by snapping to a grid in increments.

You can see an example of constraints being applied in our Kitchen Sink Example

Drag Handle

By default, a drag gesture on any portion of the source element will initiate a drag on the source. A handle allows specific portion/s of the element to be specified by using a css selector. This is useful in 2 main scenarios:

  1. The source should only be dragged in a certain area, for example, the title bar of a window.

  2. The source has many repeated elements that should trigger a drag with unique data, for example a dataview.

You can see an example of constraints being applied in our Kitchen Sink Example

Proxies

A drag proxy is a visual representation show on screen while a drag is in progress. The proxy element (if specified) follows the mouse cursor. There are currently 3 implementations provided in this namespace:

  1. Original (the default) - The element of the source is moved.

  2. Placeholder - A new element is created and the source element is left in place.

  3. None - No proxy element is shown. This is typically used in conjunction with Source events to display drag information.

Events/Template Methods

The following events and template methods on the source are available at the specified points in the drag cycle:

  • beforedragstart/onBeforeDragStart, can be cancelled by returning false.

  • dragstart/onDragStart

  • dragmove/onDragMove

  • dragend/onDragEnd

  • dragcancel/onDragCancel

Ext.drag.Target

A drag target represents an element that can receive a drop from a source. Most of its functionality will be described in the data exchange and interaction between sources/targets sections.

Events/Template Methods

The following events and template methods on the source are available at the specified points in the drag cycle:

  • dragenter/onDragEnter

  • dragmove/onDragMove

  • dragleave/onDragLeave

  • beforedrop/onBeforeDrop, can be cancelled by returning false.

  • drop/onDrop

Ext.data.Info

This class acts as a mediator and information holder for the lifetime of a single drag. It holds all information regarding a particular drag. It also manages data exchange for the drag. This class is passed to all relevant events/template methods throughout the drag/drop cycle.

Describing Data

Drag/drop provides the mechanics for moving elements and receiving events, however it doesn't describe the underlying meaning of those actions. This section discusses working with that data.

General

Keyed Data

Similar to the HTML5 drag API, data is specified as a set key/value pair. The key is used to indicate the type of data being passed. The key is is not restricted in value, but will typically refer to the data type (text/image) or the business logic objects (users/orders). There can be many key/value pairs for a single drag operation. For each key added to the setData method, it will also be added to the types Array on the info object to interrogate the available types.

This architecture is useful for several reasons:

  • It allows targets to quickly decide whether or not they have interest in a particular source. If some drag data is marked as "csv", a drop target that is a table or grid may be able to consume that data, but it will probably not be useful to a text field.

  • It allows the data to differ depending on the target. Consider an image type being dragged. 2 keys could be set, to allow consumption by differing targets. When the drop occurs on a text field target, it can consume the text data. On a placeholder image target, it can read the blob data and display the image:

    describe: function(info) {

      // The text link to the image
      info.setData('text', theImage.link); 
    
      // The binary image data
      info.setData('image', toBlob(theImage)); 
    

    }

Data Availability

Data is available for consumption via the getData method on the info object. This method will throw an exception if it is called before the drop completes. Only the type of data may be interrogated beforehand. This is done for 2 reasons:

  • For consistency with the HTML5 drag API (the same restriction applies)

  • The data may be expensive to produce or need to be retrieved from a remote source, so it is useful to restrict access until it's required.

However, it is still possible to have data on the info object that is accessible during the drag. The info object persists throughout the entire drag, so adding properties can occur at any point:

describe: function(info) {
    info.userRecords = getTheRecords();
}

Specifying Data

When a drag initiates, the describe method is called on the source. The data for the drag should be specified here. This is expected to be implemented by the user. The describe method receives the info object.

setData

The setData method is called with 2 parameters, a string key that describes the data and a value. The value can be any data value data type (string, number, object, array). It can also be a function which will be executed to produce the data when a call to getData is made. Note that calls to getData are limited to when the drop completes.

describe: function(info) {
    // Set immediately available data
    info.setData('userId', user.id);

    // Setup a function to retrieve the data from the server on drop
    info.setData('userInfo', function() {
        var options = {}; // ajax options
        return Ext.Ajax.request(o);
    });
}

Info Properties

Alternatively, if the data is immediately available or easy to construct it can be pushed as a property directly on the info object. This data will be available at any time during the lifetime of the drag operation.

describe: function(info) {
    info.userRecords = getTheRecords();
}

Consuming Data

getData

getData should be called from the drop listener or onDrop template method to retrieve data. This method accepts a single argument, the key of the data specified from setData. The value returned from getData will always be a Promise, regardless of the underlying type. Using the data-set from above:

listeners: {
    drop: function(target, info) {
        info.getData('userId').then(function(v) {
            console.log(v);
        });

        info.getData('userInfo').then(function(response) {
            // The ajax response
        }).catch(function() {
            // Oh no!
        });
    }
}

In this case, the userId value will be available so the promise will resolve immediately. In the case of the ajax data, it will wait until the request returns.

Info Properties

For properties stored on the info object, they can be accessed using normal property access:

listeners: {
    drop: function(target, info) {
        console.log(info.userRecords);
    }
}

Interactions Between Sources and Targets

By default, all sources can interact with all targets. This can be restricted in a number of ways. A drag on a target is considered valid once a series of conditions is met. Targets will still receive events for invalid targets, however the valid flag on the info object will be false.

Disabled State

If a Source is disabled, it is not possible to drag. If a Target is disabled, any source is not valid.

Groups

Both Sources and Targets can belong to groups. A group is an identifier that indicates which items can interact with each other. A group can be a single string or an array of strings. Items belonging to the same groups can interact. The following rules apply:

  • If neither source nor target has groups, the drag is valid.

  • If the source and the target have groups and the groups intersect, the drag is valid.

  • If the source and the target have groups but no intersection, the drag is invalid.

  • If the source has groups but the target does not, the drag is invalid.

  • If the source does not have groups but the target does, the drag is invalid.

Below are some example source group configurations:

// Can only be dropped on targets with no groups
{}

// Can only be dropped on targets that contain group1
{ groups: 'group1' }

// Can be dropped on targets that contain group1 or group2
{ groups: ['group1', 'group2'] }

Accepts

Target has a configurable method accepts which is called when a Source first enters the target. This allows the Target to determine on a per source basis whether it will interact with it. The accepts method is passed the info object and should return a boolean indicating whether it will accept the source. Note that the getData method cannot be called here, however any properties on the info object may be accessed.

// Interrogating types
{
    accepts: function(info) {
        return info.types.indexOf('userRecord') > -1;
    }
}

// Accessing property data
new Ext.drag.Source({
    describe: function(info) {
        info.total = 100;
    }
});

new Ext.drag.Target({
    accepts: function(info) {
        return info.total > 75;
    }
});

Component Integration

When using the drag namespace in conjunction with components, it is often useful to wrap the parts in plugins or other containers to provide a better contextual API. The following code sample implements the ability to drag rows in the Modern Grid.

The code doesn't handle any of the mechanics of doing the drag/drop, however it does provide a better API for using with components, as well as filling in some of the lower level detail needed to make the drag function.

In this example, we'll integrate a custom Drag and Drop plugin with a Grid. We'll then disable drag for anything with a record name of "Bar".

Conclusion

As Ext JS continues to evolve, the Ext.drag API will be incorporated in plugins like the example above and more. Today, Ext.drag offers a convenient way to handle drag-and-drop for both Toolkits and plays nicely with the standard HTML5 API.

Ext JS 7.0.0