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 and inheritance. 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.

Sencha Touch 2.4

Guides
API
top

Using AJAX with Sencha Touch

Sencha Touch provides a variety of convenient ways to get data into and out of your application. All of the data-bound Components such as Lists, Nested Lists, and DataViews use Stores, which are easily configured to fetch and save data to a large variety of sources. We will look at managing data with stores later on, but first let us start with how to generate simple AJAX requests.

Simple Requests with Ext.Ajax

Because of browser security restrictions, AJAX requests are usually made to urls on the same domain as your application. For example, if your application is found at http://myapp.com, you can send AJAX requests to urls such as http://myapp.com/login.php and http://myapp.com/products/1.json, but not to other domains such as http://google.com. However, Sencha Touch provides some alternatives to get around this limitation, as shown in the final part of this guide (Cross-Domain Requests and JSON-P).

The following code shows an AJAX request to load data form an url on the same domain:

Ext.Ajax.request({
    url: 'myUrl',
    callback: function(options, success, response) {
        console.log(response.responseText);
    }
});

Assuming that your app is on http://myapp.com, the previous code sends a GET request to http://myapp.com/myUrl. Since AJAX calls are asynchronous, once the response comes back, the callback function is called with the response. In this example the callback function logs the contents of the response to the console when the request has finished.

AJAX Options

Ext.Ajax takes a wide variety of options, including setting the method (GET, POST, PUT, or DELETE), sending headers, and setting params to be sent in the url. The following code sets the method such that a POST request is sent instead of a GET:

Ext.Ajax.request({
    url: 'myUrl',
    method: 'POST',

    callback: function(options, success, response) {
        console.log(response.responseText);
    }
});

Sending parameters done as shown in the following example:

Ext.Ajax.request({
    url: 'myUrl',

    params: {
        username: 'Ed',
        password: 'not a good place to put a password'
    },

    callback: function(options, success, response) {
        console.log(response.responseText);
    }
});

When setting parameters like in this example, the request is automatically sent as a POST with the params object sent as form data. The previous request above is like submitting a form with username and password fields.

If we wanted to send this as a GET request instead, we would have to specify the method again, in which case our params are automatically escaped and appended to the url:

Ext.Ajax.request({
    url: 'myUrl',
    method: 'GET',

    params: {
        username: 'Ed',
        password: 'bad place for a password'
    },

    callback: function(options, success, response) {
        console.log(response.responseText);
    }
});

The previous code sample generates the following request:

http://mywebsite.com/myUrl?_dc=1329443875411&username=Ed&password=bad%20place%20for%20a%20password

You may have noticed that our request created an url that contained "_dc=1329443875411". When you make a GET request like this, many web servers cache the response and send you back the same response every time you make the request. Although this speeds the web up, it is not always what you want. In fact in applications this is rarely what you want, so we "bust" the cache by adding a timestamp to every request. This tells the web server to treat it like a fresh, uncached request.

If you want to turn this behavior off, we ccould set disableCaching to false, as shown in the following code sample:

Ext.Ajax.request({
    url: 'myUrl',
    method: 'GET',
    disableCaching: false,

    params: {
        username: 'Ed',
        password: 'bad place for a password'
    },

    callback: function(options, success, response) {
        console.log(response.responseText);
    }
});

Since the request no longer contains the cache busting string, it looks like the following string:

http://mywebsite.com/myUrl?username=Ed&password=bad%20place%20for%20a%20password

Sending Headers

Another option related to customizing the request is the headers option. This enables you to send any custom headers to your server, which is often useful when the web server returns different content based on these headers. For example, if your web server returns JSON, XML, or CSV based on the header it is passed, we can request JSON like in the following example:

Ext.Ajax.request({
    url: 'myUrl',

    headers: {
        "Content-Type": "application/json"
    },

    callback: function(options, success, response) {
        console.log(response.responseText);
    }
});

If you create a request like this and inspect it in Firebug/web inspector, you will see that the Content-Type header has been set to application/json. Your web server can pick up on this and send you the right response. You can pass any number of headers you like into the headers option.

Callback Options

Not every AJAX request succeeds: sometimes the server is down, or your internet connection drops, or something else bad happens. Ext.Ajax allows you to specify separate callbacks for each of these cases:

Ext.Ajax.request({
    url: 'myUrl',

    success: function(response) {
        console.log("Spiffing, everything worked");
    },

    failure: function(response) {
        console.log("Curses, something terrible happened");
    }
});

These do exactly what you would expect them to do, and hopefully most of the time it is your success callback that gets called. It is pretty common to provide a success callback that updates the UI or does whatever else is needed by the application flow, and a failure handler that either resends the request or alerts the user that something went wrong.

You can provide success/failure and callback at the same time, so for this request the success function is called first (if everything was ok), followed by the main callback function. In the case of failure, the failure function is called first, followed by callback:

Ext.Ajax.request({
    url: 'myUrl',

    success: function(response) {
        console.log("Spiffing, everything worked");
    },

    failure: function(response) {
        console.log("Curses, something terrible happened");
    },

    callback: function(options, success, response) {
        console.log("It is what it is");
    }
});

Timeouts and Aborting Requests

Another way requests can fail is when the server took too long to respond and the request timed out. In this case your failure function is called, and the request object it is passed has the timedout variable set to true:

Ext.Ajax.request({
    url: 'myUrl',

    failure: function(response) {
        console.log(response.timedout); // logs true
    }
});

By default the timeout threshold is 30 seconds, but you can specify it for every request by setting the timeout value in millisecond. In the following case the request will give up after 5 seconds:

Ext.Ajax.request({
    url: 'myUrl',
    timeout: 5000,

    failure: function(response) {
        console.log(response.timedout); // logs true
    }
});

It is also possible to abort requests that are currently outstanding. In order to do this, you need to save a reference to the request object that Ext.Ajax.request returns, as shown in the following code sample:

var myRequest = Ext.Ajax.request({
    url: 'myUrl',

    failure: function(response) {
        console.log(response.aborted); // logs true
    }
});

Ext.Ajax.abort(myRequest);

This time the failure callback is called and its response.aborted property is set. You can use all of the error handling above in your apps:

Ext.Ajax.request({
    url: 'myUrl',

    failure: function(response) {
        if (response.timedout) {
            Ext.Msg.alert('Timeout', "The server timed out :(");
        } else if (response.aborted) {
            Ext.Msg.alert('Aborted', "Looks like you aborted the request");
        } else {
            Ext.Msg.alert('Bad', "Something went wrong with your request");
        }
    }
});

Cross-Domain Requests

A relatively new capability of modern browsers is called CORS, which stands for Cross-Origin Resource Sharing. This allows you to send requests to other domains, without the usual security restrictions enforced by the browser. Sencha Touch provides support for CORS, although you will probably need to configure your web server in order to enable it. If you are not familiar with the required actions for setting up your web server for CORS, a quick web search should give you plenty of answers.

Assuming your server is set up, sending a CORS request is easy:

Ext.Ajax.request({
    url: 'http://www.somedomain.com/some/awesome/url.php',
    withCredentials: true,
    useDefaultXhrHeader: false
});

Form Uploads

The final topic covered in this guide is uploading forms, a functionality that is illustrated in the following sample code:

Ext.Ajax.request({
    url: 'myUrl',
    form: 'myFormId',

    callback: function(options, success, response) {
        if (success) {
            Ext.Msg.alert('Success', 'We got your form submission');
        } else {
            Ext.Msg.alert('Fail', 'Hmm, that did not work');
        }
    }
});

This finds a <form> tag on the page with id="myFormId", retrieves its data and puts it into the request params object, as shown at the start of this guide. Then it submits it to the specified url and calls your callbacks like normal.

Sencha Touch 2.4

Ext JS
Sencha Test
Cmd
Sencha Themer
GXT
IDE Plugins
Sencha Inspector
Architect
Sencha Fiddle
Touch
Offline Documentation

Sencha Test

2.0.1 2.0.0 1.0.3

Cmd

Cmd

Sencha Themer

1.1.0 1.0.2

GXT

4.x 3.x

IDE Plugins

IDE Plugins

Sencha Inspector

Sencha Inspector

Sencha Fiddle

Sencha Fiddle

Offline Documentation

Offline Documentation