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 DataViews in Sencha Touch

DataView makes it easy to create dynamically a number of components, usually based off a store. It is used for rendering data from your server back-end or any other data source, and it powers components such as list.

You can use dataView whenever you want to show repeatedly sets of the same component, for example in cases such as the following:

  • A list of messages in an email app
  • A list of the latest news or tweets
  • A tiled set of albums in an HTML5 music player

Creating a Simple DataView

At its simplest, a dataView is a store full of data and a template that is used to render each store item, as illustrated by the following example:

In this example we defined the store inline, so all data is local and therefore does not have to be loaded from a server. For each of the data items defined in the store, dataView renders a div and passes in the name and age data. The div uses the specified itemTpl and renders the data inside the curly bracket placeholders.

Because dataView is integrated with store, any changes to the store are immediately reflected on the screen. For example, if we added a new record to the store, it would be rendered into our dataView:

touchTeam.getStore().add({
    name: 'Liz Lemmons',
    age: 33
});

After adding the new record as shown in the previous code sample, we do not have to manually update the dataView, since it is automatically updated. The same would happen if we modified one of the existing records in the store:

touchTeam.getStore().getAt(0).set('age', 42);

This will get the first record in the store and change age to 42 and automatically update the screen content.

Loading Data from a Server

We often want to load data from our server or some other web service, so that we do not have to hard-code the data content locally. Let us say we wanted to load the latest Sencha forum threads into a dataView, and for each thread render the thread title. To do this we need to modify the dataView store and itemTpl as follows:

In this example, the dataView no longer contains data items, instead we have provided a proxy, which fetches the data. In this case we used a JSON-P proxy that loads data using Sencha's JSON-P forum results. We also specified the title for each thread, and used Store's autoLoad configuration to load the data automatically. Finally, we configured a Reader to decode the response from Sencha.com, indicating it to expect JSON and that the threads are found in the 'topics' part of the JSON response.

Styling a DataView

You may have realized by now that although our dataView is displaying data from our store, it does not have any default styling. The lack of default styling is by design, but adding custom CSS is very simple. dataView has two configurations that support targeting your custom CSS to the view: baseCls and itemCls. baseCls is used to add a className around the outer element of the dataView. The itemCls you provide is added onto each item that is rendered into our dataView.

If you do not specify an itemCls, it automatically takes the baseCls configuration (which defaults to x-dataview) and prepends -item to it. As a result, each item will have a className of x-dataview-item.

Before adding the configuration, we need to create the custom CSS shown in the following example:

.my-dataview-item {
    background: #ddd;
    padding: 1em;
    border-bottom: 1px solid #ccc;
}
.my-dataview-item img {
    float: left;
    margin-right: 1em;
}
.my-dataview-item h2 {
    font-weight: bold;
}

Once the CSS is complete, we can go back to our previous JSONP example and add the baseCls configuration:

Ext.create('Ext.DataView', {
    fullscreen: true,
    store: store,
    itemTpl: '<p>{title}</p>',
    baseCls: 'my-dataview',
    //As described above, we don't need to set itemCls in most 
    //cases as it will already add a className
    //generated from the baseCls to each item.
    //itemCls: 'my-dataview-item'                
});

Component DataView

In the previous example we created a dataView with an itemTpl, which means each item is rendered as a basic div from a XTemplate. However, sometimes you need each item to be a component, so you can provide a rich UI for users. In Sencha Touch, we introduced the useComponents configuration which allows you to address this scenario.

Creating a component dataView is very similar to creating a normal template-based dataView as previously shown, however you must define the item view used when rendering each item in your list. Each of the store's records will translate into a dataItem, which extends from a container, so you can have multiple components inside of it. In this example we're using a custom updateRecord method implementation that updates our DataItems' Components based on the data values:

Another more advanced example, using a datamap:

Ext.define('MyListItem', {
    extend: 'Ext.dataview.component.DataItem',
    requires: ['Ext.Button'],
    xtype: 'mylistitem',

    config: {
        nameButton: true,

        dataMap: {
            getNameButton: {
                setText: 'name'
            }
        }
    },

    applyNameButton: function(config) {
        return Ext.factory(config, Ext.Button, this.getNameButton());
    },

    updateNameButton: function(newNameButton, oldNameButton) {
        if (oldNameButton) {
            this.remove(oldNameButton);
        }

        if (newNameButton) {
            this.add(newNameButton);
        }
    }
});

This example shows how to define a component-based dataView item component. There are a few important notes about this example:

  • We must extend dataItem for each item. This is an abstract class which handles the record handling for each item.

  • Following the extend code we require Ext.Button inside the item component.

  • We specify the xtype for this item component.

  • Inside the config block we define the nameButton item. This custom configuration added to the component will be transformed into a button by the class system. By default we set it to true , but this could also be a configuration block. This configuration automatically generates getters and setters for the nameButton item.

  • We define the datamap. The dataMap is a map between the data of a model and this view. The getNameButton is the getter for the instance you want to update; so in this case we want to get the nameButton configuration of this component. Inside that block we then give it the setter for that instance, setText in this case and give it the field of the record we are passing. As a result, once this item component gets a record, it gets the nameButton and then calls setText with the name value of the record.

  • Finally we define the apply method for the nameButton item. The apply method uses factory. That instance is then returned, which then causes updateNameButton to be called. The updateNameButton method removes the old nameButton instance if it exists, and adds the new nameButton instance.

After having created the item component, we can create the component dataview, similar to previous examples.

Ext.create('Ext.DataView', {
    fullscreen: true,

    store: {
        fields: ['name', 'age'],
        data: [
            {name: 'Greg',  age: 100},
            {name: 'Brandon',   age: 21},
            {name: 'Scott',   age: 21},
            {name: 'Gary', age: 24},
            {name: 'Fred', age: 24},
            {name: 'Seth',   age: 26},
            {name: 'Kevin',   age: 26},
            {name: 'Israel',   age: 26},
            {name: 'Mitch', age: 26}
        ]
    },

    useComponents: true,
    defaultType: 'mylistitem'
});

This code has two key additions. First, we added the useComponents configuration and set it to true. Second, we set the defaultType configuration to the previously created mylistitem item component. This tells the dataview to use the defined item component as the view for each item.

If we run this code together, we can see the component dataview in action.

The great benefit of this approach is the flexibility it adds to your dataviews. Since each item component has access to its own Ext.dataview.component.DataItem#record, you can do just about anything with it.

In the following example we add to the nameButton an event listener to the tap event, which alerts the user with the age of the selected person.

Ext.define('MyListItem', {
    //...

    updateNameButton: function(newNameButton, oldNameButton) {
        if (oldNameButton) {
            this.remove(oldNameButton);
        }

        if (newNameButton) {
            // add an event listeners for the `tap` event onto the new button, and
            // tell it to call the onNameButtonTap method
            // when it happens
            newNameButton.on('tap', this.onNameButtonTap, this);

            this.add(newNameButton);
        }
    },

    onNameButtonTap: function(button, e) {
        var record = this.getRecord();

        Ext.Msg.alert(
            record.get('name'), // the title of the alert
            "The age of this person is: " + record.get('age') 
            // the message of the alert
        );
    }
});

Finally, after adding this code to our previous example, we get the following finished result:

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.0 EA 1.0.3

Cmd

Cmd

Sencha Themer

1.1.0 EA 1.0.2

GXT

5.x EA 4.x 3.x

IDE Plugins

IDE Plugins

Sencha Inspector

Sencha Inspector

Sencha Fiddle

Sencha Fiddle

Offline Documentation

Offline Documentation