ExtJS v4 – Getting Started

The following article will walk through basic concepts and how to get a dynamic page up and running quickly. Let’s get start with something simple now.

Project Setup



The basic web structure here refer to how you arrange the web resources

  • Create a project folder. Eg C:\Ext-workspace\webapp\
  • Create a index.html files put under the webapp.
  • Create a javascript files and named it as application.js that we will used it later.
  • Create a lib folder and place all the extjs files inside
  • Create the resource folder for images and css
  • Create the user package name under the webapp/user
  • Create the controller, model, store and view folder under the module package
  1.  
  2. + [webapp]
  3.    + index.html
  4.    + application.js  
  5.    + [lib]  <— ExtJS lib
  6.           + [extjs]
  7.    + [resources]
  8.           + [css]
  9.           + [images]
  10.    + [user]   <— module package name  
  11.           + [controller]
  12.           + [model]
  13.           + [store]
  14.           + [view]
  15.  


Everything start from “Hello World!”

Copy and paste the code below into the index.html

index.html

  1. <html>
  2. <head>
  3.    <title>Home</title>
  4.    <link rel="stylesheet" type="text/css" href="lib/extjs/resources/css/ext-all.css" />
  5.    <script type="text/javascript" src="lib/extjs/ext-debug.js"></script>
  6.    <script type="text/javascript" src="application.js" /></script>
  7. </head>
  8. <body> 
  9. </body>
  10. </html>

Copy and paste the code below into the application.js

Application.js

  1.  
  2. Ext.application({
  3.     name: ‘Example’,
  4.     launch: function() {
  5.         Ext.create(‘Ext.container.Viewport’, {
  6.             layout: ‘fit’,
  7.             items: [
  8.                 {   title: ‘Hello Ext’,
  9.                     html : ‘Hello! Welcome to ext js’
  10.                 }
  11.             ]
  12.         });
  13.     }
  14. });


Explaination

Ext.application { … } is a MVC approach to get start a single page application and display the content in a Viewport.

Ext.application instance given a name as ‘Example’ also known as namespace and it can be used by references for controller, view, model and other resources.

Ext.create start instantiate a class ‘Ext.container.Viewport’ as a string name parameter and set the fit layout and given the HTML content property.

A Viewport refer to a browser display area, it will auto resize accordingly. Whenever it’s ready by application, it will launch a function call to create the Viewport container to the document body.

The fit layout was using here mean to 100% screen fit. items[ ] refer to a group of properties where it defined title: is ‘Hello ExtJS’ and html: is the content.






Run on the server you should see something like above.

Download the example here

You can leave a response, or trackback from your own site.

Leave a Reply

Security Code: