Ext.js - Components Inside Container



Components inside container: We can have multiple components inside the container.

Syntax

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

var component1 = Ext.create('Ext.Component', {
   html:'First Component'
});
Ext.create('Ext.container.Container', {
   renderTo: Ext.getBody(),
   items: [component1]
});

You can have components as an item inside a container.

Example

Following is a simple example showing the components inside the 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'
            });
            Ext.create('Ext.container.Container', {
               renderTo: Ext.getBody(),
               title: 'Container',
               border: 1,
               width: '50%',
               style: {borderStyle: 'solid', borderWidth: '2px' },
               items: [component1, component2,  component3]
            });
         });
      </script>
   </head>
   
   <body>
   </body>
</html>

The above program will produce the following result −

extjs_containers.htm
Advertisements