Before reading this article please goes through the following articles.
- Introduction to Sencha Touch
- Hello World App using Sencha Touch 2
- Sample form application using Sencha Touch 2
- Dealing with containers in Sencha Touch 2
Introduction
In the last article, we worked with container controls in Sencha Touch 2. In this article, we will have a look at data-bound controls provided by Sencha Touch. All of us know what data-bound is. As in our first article, we saw that Sencha Touch is a mobile application development framework. So here in Sencha Touch, we do not have a data-grid kind of controls. But the latest version of Sencha Touch provides a grid control also. So let’s get started with the basic data-bound controls for data.
Data-View
Sencha Touch provides a control called Data-view that is very useful for displaying some data from a database or service. Use the dataview component when you need to show a list of mails, a list of tweets and so on. Data-view is very useful because it creates many components dynamically. You can design each data-row as needed by applying extra CSS. The following example shows how to create a data-view.
- var touchTeam = Ext.create('Ext.DataView', {
- fullscreen: true,
- store: {
- fields: ['Name', 'Articles'],
- data: [
- { Name: 'Mahesh', Articles: 500 },
- { Name: 'DJ', Articles: 500 },
- { Name: 'Dinesh', Articles: 200 },
- { Name: 'Krishna', Articles: 95 }
- ]
- },
- itemTpl: '<div>{Name} has written {Articles} on C-sharp corner.</div>'
- });
- Ext.Viewport.add(touchTeam);
In the above snippet you can see we have created a dataview control by instantiating the Ext.DataView class. A Data-View has many properties as do other controls that we saw in our previous chapters. Here we will discuss a couple of properties that are necessary to create a data-view.
In the first place, we have a store. A store is the way to provide a data-source for the data-bound control in Sencha Touch. In the store we can define static data or pull data from a back-end server. We will see a store in depth when we move to MVC in Sencha Touch. Here, for now, we will simply display the static data. As in ASP.NET for any data-bound control, we provide a data source property; in Sencha, we have the store property to specify the data-source.
In all data-bound controls, we have the store property. Next, we can see itemTpl, which is one more important property for all data-bound controls. In itemTpl we can specify how the row will be rendered on the screen. Here we can create an HTML element directly or we can create some XTemplate that we will see in later chapters. For itemTpl you can apply the CSS and make your data-view look good.


Join the conversation! Your thoughts help the community grow.