Ext.js - Container Inside Container



Container inside container: We can have containers inside other containers as a component for the parent container along with other components.

Syntax

Following is the simple syntax to use Container inside the container.

var container = Ext.create('Ext.container.Container', {
   items: [component3, component4]
});
Ext.create('Ext.container.Container', {
   renderTo: Ext.getBody(),
   items: [container]
});

You can have a container as an item inside the other container.

Example

Following is a simple example showing a container inside a container.

<!DOCTYPE html>
<html>
   <head>
      <link href="/?originalUrl=https%3A%2F%2Fcdnjs.cloudflare.com%2Fajax%2Flibs%2Fextjs%2F6.0.0%2Fclassic%2Ftheme-classic%2Fresources%2Ftheme-classic-all.css" 
         rel = "stylesheet" />
      <script type = "text/javascript" 
         src="/?originalUrl=https%3A%2F%2Fcdnjs.cloudflare.com%2Fajax%2Flibs%2Fextjs%2F6.0.0%2Fext-all.js"></script>

      <script type = "text/javascript">
         Ext.onReady(function () {
            var component1 = Ext.create('Ext.Component', {
               html:'First Component'
            });
            var component2 = Ext.create('Ext.Component', {
               html: 'Second Component'
            });
            var component3 = Ext.create('Ext.Component', {
               html: 'Third Component'
            });
            var component4 = Ext.create('Ext.Component', {
               html: 'Fourth Component'
            });
            var container = Ext.create('Ext.container.Container', {
               style: {borderStyle: 'solid', borderWidth: '2px' },
               width: '50%',
               items: [component3, component4]
            });
            Ext.create('Ext.container.Container', {
               renderTo: Ext.getBody(),
               title: 'Container',
               border: 1,
               width: '50%',
               style: {borderStyle: 'solid', borderWidth: '2px' },
               items: [component1, component2,  container]
            });
         });
      </script>
   </head>
   
   <body>
   </body>
</html>

The above program will produce the following result −

extjs_containers.htm
Advertisements