Before reading this article please go through the following articles.
- Introduction to Sencha Touch 2
- Hello World App using Sencha Touch 2
- Sampleform application using Sencha Touch 2
Introduction
In the last article we developed a sample form application using Sencha Touch 2. In this article we will see the container available in Sencha Touch 2. As a developer you are all aware of containers.
What are containers?
We all know that containers are nothing but controls that can have child controls inside them. Containers are very useful when we need to arrange the child controls or make a group of various controls. Containers are the option for developers for that. For example a panel that is one of the container controls that can have child controls arranged inside it. In Sencha Touch we have various container controls; we will look at those controls one by one.
1. Component
A Component is the base control for all available controls in Sencha Touch. Every control you create in Sencha Touch 2 is nothing but a component. A Component has the ability to be rendered on the form, show or hide themselves and enable or disable themselves. You can create a component using xtype as "component".
2. Container
A Container is inherited from Component and has the all abilities that a Component has. A Container has one more extra feature that can nest other container controls inside them, like panels, tabpanels and so on. As we know, when we are developing a web app we need many containers, like panels and tabpanels. Container controls allow you to arrange the child controls inside them. You can create a container using xtype as "container". In Sencha Touch 2 all the lower level containers like panels, tabpanels and carousels are inherited from container only. In Sencha Touch 2 a container allows you to add or remove child components at runtime. A Container has the ability to specify the layout as well. We will talk about layouts further in this article.
3. Panels
Like other frameworks, Sencha Touch 2 also provides a basic container control, in other words Panel. In a Sencha Touch 2 app when you need to create overlapping controls then panels are the best way to do that. You can use the panels for arranging the page child controls also. Panels have the ability to provide the layouts. Take the following example that creates a main panel and inside it creates two side-by-side child panels.
- var mainPanel = Ext.create("Ext.Panel",
- {
- id: 'mainpanle', height: '100%', width: '100%', layout:
- {
- type: 'hbox'
- },
- items: [{//items of formpanel
- xtype: 'panel',
- layout: 'vbox',
- html: 'Panel One',
- width:'30%',
- style: 'background-color: #5E99CC;'
- },
- {
- xtype: 'panel',
- layout: 'vbox',
- html: 'Panel Two',
- width:'70%'
- }
- ]
- });
- Ext.Viewport.add(mainPanel);
- }

Join the conversation! Your thoughts help the community grow.