Showing posts with label extjs tutorial. Show all posts
Showing posts with label extjs tutorial. Show all posts

Sunday, February 10, 2013

Difference Between ext.js & ext-all.js

When we start the development of a new Ext JS project, the first thing we have to do is to add the imports of Ext JS files on the HTML page. If we choose a version of the ext-all file, the browser will load the entire Ext JS framework. If we choose a version of the ext.js file, the browser will load the minimum code required to execute the application, and we can make use of the new dynamic loading feature.

For development and testing, we can use ext.js, because it will use only the required Ext JS code to run the application; but, we cannot forget to add the src folder to the application extjs directory. For production, we can use the ext-all.js file, because it already contains the entire Ext JS framework and has good performance.

There is also a file named bootstrap.js; instead of importing ext-all.js into your HTML page, you can import bootstrap.js. The only thing that this file does is import ext-all.js or ext-all-debug.js, depending on the environment you are using. It will load ext-all-debug.js in the following cases:

  1. Current hostname is localhost.
  2. Current hostname is an IP(v4) address.
  3. Current protocol is a file.
  4. Otherwise, bootstrap will load the ext-all.js file.

Continue Reading...

Thursday, December 13, 2012

Extjs 4 HBox Layout

The HBox layout organizes its children horizontally across the container. You can set two optional configurations to organize the child's width and height across the parent's body.

The flex configuration will tell the parent Component how to organize the child Components horizontally, based on the relative flex configuration. The align configuration will tell the child Components how to use the height across the parent. Let's consider that we have two panels and we want to display these panels inside a Window:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Extjs 4 HBox Layout Example</title>

<link rel="stylesheet" type="text/css" href="http://extjs-public.googlecode.com/svn/extjs-4.x/release/resources/css/ext-all.css" />

<script type="text/javascript" src="http://extjs-public.googlecode.com/svn/extjs-4.x/include/ext-all.js"></script>

<script type="text/javascript">

Ext.onReady(function(){

 var panel1 = Ext.create('Ext.panel.Panel', {
  title: 'Panel 1',
  html: 'Panel 1',
  flex: 1
 });

 var panel2 = Ext.create('Ext.panel.Panel', {
  title: 'Panel 2',
  html: 'Panel 2',
  flex: 3
 });

 var hbox = Ext.create('Ext.window.Window', {
  title: 'HBox Layout -  Tutorial Jinni',
  width: 300,
  height:100,
  layout: {
         type: 'hbox',
         align: 'stretch'
     },
  defaults: {
   bodyStyle: 'padding:10px'
     },
  items: [panel1, panel2]
 });
 hbox.show();
});

</script>
</head>
<body>
</body>
</html>
In the preceding code, we have two panels. Each panel has its title and HTML content. Each one also has a flex configuration. The first panel configured flex as 1 and the second panel configured the flex config as 3. The Window will sum these flex configs (in this example, the total will be 4) and will distribute the horizontal space relative to each child. The first panel will get one-fourth (25%) of the window's horizontal space and the second panel will get three-fourths (75%) of the window's horizontal space.

In the Window declaration, we have the layout config. It tells the Window that we are going to use the hbox layout and align of the child Components will be stretch, meaning that we can use the full height of the window's vertical space.

When we execute the code, the following will be the output:



If we try to resize the Window, children will be resized as well, according to their configuration.
Continue Reading...

Friday, November 16, 2012

Extjs 4 Absolute Layout

The Absolute Layout class is a subclass of Anchor Layout, and that is why it inherits the anchoring feature from its mother class. Like the Anchor Layout, the Absolute Layout also allows you to set an x and y configuration, which means the location of the Component will be located in its parent's body.

Let's try to add a Panel in a Window using the Absolute Layout:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Extjs 4 Absolute Layout Example</title>

<link rel="stylesheet" type="text/css" href="http://extjs-public.googlecode.com/svn/extjs-4.x/release/resources/css/ext-all.css" />

<script type="text/javascript" src="http://extjs-public.googlecode.com/svn/extjs-4.x/include/ext-all.js"></script>

<script type="text/javascript">

Ext.onReady(function(){

 var panel1 = Ext.create('Ext.panel.Panel', {
  title: 'Panel 1',
  html: 'x: 10; y: 10 - anchor: 80% 80%',
  anchor:'80% 80%',
  x: 10,
        y: 10
 });

 var absolute = Ext.create('Ext.window.Window', {
  title: 'Absolute Layout Example - Tutorial Jinni',
  width: 300,
  height: 200,
  layout:'absolute',
  defaults: {
         bodyStyle: 'padding:10px'
     },
  items: [panel1]
 });
 absolute.show();
});

</script>
</head>

<body>
</body>
</html>
In the preceding code, we have a Window with a title, width(300 pixels), height (200 pixels), using the Absolute Layout. This Window contains only one Panel as the child item. The panel we declared as the Window item is panel1. This panel has a title and HTML content. We set the anchor as 80%of the parent's width and 80%of the parent's height. We also set the position of panel1 in its parent's body, which is x=10 and y =10.

The upper-left corner of the Window will be x=0 and y=0.

The code output will be as follows:

Extjs 4 Absolute Layout


If you re-size the outer container (Window), its child is going to be re-sized according to its anchor rule. The position of the child items will not change with the re-sizing.

Continue Reading...

Wednesday, November 14, 2012

Extjs 4 Anchor Layout

The Anchor Layout allows anchoring the container's children according to its dimension. If you re-size the outer container, all its children will be automatically re-sized according to the children's anchor rules. Just like the Auto Layout, the Anchor Layout also stacks its children according to the order they were added or declared in, in the items config.

For example, we have four panels and we want to add them in a Window using the Anchor Layout:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Extjs 4 Anchor Layout Example</title>

<link rel="stylesheet" type="text/css" href="http://extjs-public.googlecode.com/svn/extjs-4.x/release/resources/css/ext-all.css" />

<script type="text/javascript" src="http://extjs-public.googlecode.com/svn/extjs-4.x/include/ext-all.js"></script>

<script type="text/javascript">

Ext.onReady(function(){

 var panel1 = Ext.create('Ext.panel.Panel', {
  title: 'Panel 1',
  html: '100% 30%',
  anchor:'100% 30%'
 });

 var panel2 = Ext.create('Ext.panel.Panel', {
  title: 'Panel 2',
  html: '80% 25%',
  anchor:'80% 25%'
 });

 var panel3 = Ext.create('Ext.panel.Panel', {
  title: 'Panel 3',
  html: '-70 20%',
  anchor:'-70 20%'
 });

 var panel4 = Ext.create('Ext.panel.Panel', {
  title: 'Panel 4',
  html: '-30 25%',
  anchor:'-30 25%'
 });

 var anchor = Ext.create('Ext.window.Window', {
  title: 'Anchor Layout Example - Tutorial Jinni',
  width: 250,
  height:300,
  layout:'anchor',
  defaults: {
         bodyStyle: 'padding:10px'
        },
  items: [panel1, panel2, panel3, panel4]
 });
 anchor.show();
});
</script>
</head>

<body>
</body>
</html>
Let's explain the code starting from the last element declared, which is the Window named anchor. This window has a title, width(250 pixels), height(300 pixels) and is using the Anchor Layout. It also has four children declared in the items config.

Going back to the beginning of the code, we declared four panels. Each one has a title and HTML content. We also set an anchor rule for each one:

  • The first panel (panel1) has an anchor specified as 100% of the parent's width(250 pixels, originally) and 30% of the parent's height(30% of the parent's height = 30% of 300 = 90 pixels). 
  • The second panel (panel2) has an anchor specified as 80% of the parent's width(80% of 300 = 200 pixels) and 25% of the parent's height(25% of 300 = 75 pixels).
  • The third panel (panel3) has an anchor specified as -70 pixels of offset which means this panel will leave 70 pixels of space on the right side of the parent's body and 20% of the parent's height (20% of 300 = 60 pixels). 
  • The fourth panel (panel4) has an anchor specified as -30 of offset which means this panel will leave 30 pixels of space on the right side of the parent's body and 25% of the parent's height(25% of 300 = 75 pixels).
When we execute the code, the output will be as follows:


If we try to re-size the Window, all its children will be re-sized according to their anchor rules. Let's try to re-size the window to a bigger size to see what happens:


When we compare the two previous screenshots, we see that when we re-sized the window, it maintained the child panels proportional to their original size.
Continue Reading...

Tuesday, November 13, 2012

Extjs 4 Link Button

In this tutorial we will create a  Link Button by extending Extjs's Ext.Button class. The code is as follow.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Extjs 4 Link Button Example</title>

<link rel="stylesheet" type="text/css" href="http://extjs-public.googlecode.com/svn/extjs-4.x/release/resources/css/ext-all.css" />

<script type="text/javascript" src="http://extjs-public.googlecode.com/svn/extjs-4.x/include/ext-all.js"></script>

<script type="text/javascript">
Ext.onReady(function(){
 
 Ext.define('LinkButton', {
  extend: 'Ext.Button',
  xtype: 'linkbutton',
  config: {
   href:'',
   target:'',
  },
  initComponent: function () {  
   this.on('click', function(){
    window.open(this.href,this.target);
   });
  }
 });
 
 var linkButton=Ext.create('LinkButton', {
   text: 'Extjs 4 Link Button',
   scale:'large',
   href:'http://www.mobilesjinni.com/',
   target:'_self'
 });
 
 var linkButtonWindow = Ext.create('Ext.window.Window', {
  title: 'Link Button Example - Tutorial Jinni',
  width: 250,
  height: 200,
  layout:'fit',
  items: [linkButton]
 });
 
 linkButtonWindow.show();
});

</script>
</head>

<body>
</body>
</html>
when you execute the above code in the browser it will render like this

Extjs 4 Link Button

there may be other ways to implement it, i implement it using this, if you know any better solution please share.
Continue Reading...

Monday, November 12, 2012

Extjs 4 Auto Layout

Layouts have been vastly improved in EXT JS 4. The whole layout engine was rewritten, although the API is still the same; in other words, layouts are backward-compatible. The generated HTML was also updated in Ext JS 4.

The Auto Layoutis the default layout manager applied to a Container when no layout is specified.

For example, consider we have four panels and we want to organize these panels into an outer container (for example, a window)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Extjs 4 Auto Layout</title>

<link rel="stylesheet" type="text/css" href="http://extjs-public.googlecode.com/svn/extjs-4.x/release/resources/css/ext-all.css" />

<script type="text/javascript" src="http://extjs-public.googlecode.com/svn/extjs-4.x/include/ext-all.js"></script>

<script type="text/javascript">
Ext.onReady(function(){
 
 var panel1 = Ext.create('Ext.panel.Panel', {
  title: 'Panel 1',
  html: 'Panel 1',
  height: 60,
  width: 100
 });

 var panel2 = Ext.create('Ext.panel.Panel', {
  title: 'Panel 2',
  html: 'Panel 2',
  height: 80,
  width: 60
 });

 var panel3 = Ext.create('Ext.panel.Panel', {
  title: 'Panel 3',
  html: 'Panel 3',
  height: 65,
  width: 100
 });

 var panel4 = Ext.create('Ext.panel.Panel', {
  title: 'Panel 4',
  html: 'Panel 4',
  height: 70,
  width: '90%'
 });
 
 var auto = Ext.create('Ext.window.Window', {
  title: 'Auto Layout Example - Tutorial Jinni',
  width: 100,
  height: 320,
  /*layout:'auto',*/
  /* it is a good practice to define layout */
  /* for this example purpose we comment it */
  defaults: {
   bodyStyle: 'padding:15px'
     },
  items: [panel1, panel2, panel3, panel4]
 });
 
 auto.show();
});

</script>
</head>

<body>
</body>
</html>
In the preceding code, we have four simple panels; each one has a title, HTML content, height, and width. Then, we have a Window object called auto, which has a title, height, and width. We also specified the layout as auto, but you do not need to specify a layout at all. We want every child Panel(panels we declared before) content to have a padding of 15 pixels. The defaults option applies all the config settings to all added items: panel1, panel2, panel3, and panel4 (whether added to the items config or via the add and insert methods). The auto panel contains four children (the panels we declared before)—panel1, panel2, panel3, and panel4.

When you run the above code you will see the below window.

extjs 4 auto layout tutorial
Note that the child panels were added to the main Window(auto) in the order as they were declared; in other words, you must append children to the window in a specific order to use the auto layout correctly. If we try to re-size the Window, the panel will not change its size, even if we declared the last panel's (panel4) width to 90% of the Window's width, because of the properties of Auto Layout.
Continue Reading...

Thursday, March 29, 2012

Extjs 4 Hello World Tutorial

Extjs is a free and open source javascript library used for building rich internet application. Extjs is compatible with almost all major modern browsers. Extjs can be used with jQuery so there is no need to replace jQuery at the same time you can do almost everything with Extjs too. One very interesting feature of Extjs is that is comes with a very beautiful skin/theme.

Getting started is easy, as we will see in this tutorial, we need to include a CSS file and a javascript library and we are good to go with Extjs.

Out of many ways of getting Extjs, one way is to Click Here and download latest version of it, another way is to use hosted CDN. We will use the second option because it will save bandwidth and improve loading time. We are going to use googlecode.

// CSS File

<link rel="stylesheet" type="text/css" href="http://extjs-public.googlecode.com/svn/extjs-4.x/release/resources/css/ext-all.css" />

// javascript File

<script type="text/javascript" src="http://extjs-public.googlecode.com/svn/extjs-4.x/include/ext-all.js"></script>

Now lets greet our user with a simple popup.
<script type="text/javascript">

// Make sure all libraries are loaded.

Ext.onReady(function(){

// Extjs Message Box

 Ext.Msg.show({
  title: "Greeting Extjs User",
  msg: "Hello World, Welcome to Extjs. Isn't Cool?",
  icon: Ext.Msg.INFO,
  buttons: Ext.MessageBox.OK
 });
});
</script>
Save the file as index.html and run it in your browser and you will get something like this...


I very much like the skin/theme provided by Extjs. There are other themes too which I will show you in coming tutorials.

Full Source Code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Extjs 4 Hello World Tutorial</title>

<link rel="stylesheet" type="text/css" href="http://extjs-public.googlecode.com/svn/extjs-4.x/release/resources/css/ext-all.css" />

<script type="text/javascript" src="http://extjs-public.googlecode.com/svn/extjs-4.x/include/ext-all.js"></script>

<script type="text/javascript">
Ext.onReady(function(){
 Ext.Msg.show({
  title: "Greeting Extjs User",
  msg: "Hello World, Welcome to Extjs. Isn't Cool?",
  icon: Ext.Msg.INFO,
  buttons: Ext.MessageBox.OK
 });
});

</script>
</head>

<body>
</body>
</html>
Continue Reading...
 

Blog Info

A Pakistani Website by Originative Systems

Total Pageviews

Tutorial Jinni Copyright © 2015 WoodMag is Modified by Originative Systems