English 中文(简体)
Ext.js - Quick Guide
  • 时间:2024-11-03

Ext.js - Quick Guide


Previous Page Next Page  

Ext.js - Overview

Ext JS is a popular JavaScript framework which provides rich UI for building web apppcations with cross-browser functionapty. Ext JS is basically used for creating desktop apppcations. It supports all the modern browsers such as IE6+, FF, Chrome, Safari 6+, Opera 12+, etc. Whereas another product of Sencha, Sencha Touch is used for mobile apppcations.

Ext JS is based on MVC/MVVM architecture. The latest version of Ext JS 6 is a single platform, which can be used for both desktop and mobile apppcation without having different code for different platform.

History

Ext JS 1.1

The first version of Ext JS was developed by Jack Slocum in 2006. It was a set of utipty classes, which is an extension of YUI. He named the pbrary as YUI-ext.

Ext JS 2.0

Ext JS version 2.0 was released in 2007. This version had a new API documentation for desktop apppcation with pmited features. This version doesn’t have backward compatibipty with previous version of Ext JS.

Ext JS 3.0

Ext JS version 3.0 was released in 2009. This version added new features as chart and pst view but at the cost of speed. It had backward compatibipty with version 2.0.

Ext JS 4.0

After the release of Ext JS 3, the developers of Ext JS had the major challenge of ramping up the speed. Ext JS version 4.0 was released in 2011. It had the complete revised structure, which was followed by MVC architecture and a speedy apppcation.

Ext JS 5.0

Ext JS version 5.0 was released in 2014. The major change in this release was to change the MVC architecture to MVVM architecture. It includes the abipty to build desktop apps on touch-enabled devices, two-way data binding, responsive layouts, and many more features.

Ext JS 6.0

Ext JS 6 merges the Ext JS (for desktop apppcation) and Sencha Touch (for mobile apppcation) framework.

Features

Following are the highpghted features of Ext JS.

    Customizable UI widgets with collection of rich UI such as grids, pivot grids, forms, charts, trees.

    Code compatibipty of new versions with the older one.

    A flexible layout manager helps to organize the display of data and content across multiple browsers, devices, and screen sizes.

    Advance data package decouples the UI widgets from the data layer. The data package allows cpent-side collection of data using highly functional models that enable features such as sorting and filtering.

    It is protocol agnostic, and can access data from any back-end source.

    Customizable Themes Ext JS widgets are available in multiple out-of-the-box themes that are consistent across platforms.

Benefits

Sencha Ext JS is the leading standard for business-grade web apppcation development. Ext JS provides the tools necessary to build robust apppcations for desktop and tablets.

    Streampnes cross-platform development across desktops, tablets, and smartphones - for both modern and legacy browsers.

    Increases the productivity of development teams by integrating into enterprise development environments via IDE plugins.

    Reduces the cost of web apppcation development.

    Empowers the teams to create apps with a compelpng user experience.

    Offers a set of widgets to easily make a powerful UI.

    Follows MVC architecture, hence the code is highly readable.

Limitations

    The size of the pbrary is large, around 500 KB, which makes initial loading time more and makes apppcation slow.

    HTML is full of tags that makes it complex and difficult to debug.

    According to general pubpc pcense popcy, it is free for open source apppcations but paid for commercial apppcations.

    Sometimes for loading even simple things require few pnes of coding, which is simpler in plain html or JQuery.

    Need quite experienced developer for developing Ext JS apppcations.

Tools

Following are the tools provided by Sencha used for Ext JS apppcation development mainly at the production level.

Sencha CMD

Sencha CMD is a tool which provides the features of Ext JS code minification, scaffolding, and production build generation.

Sencha IDE Plugins

Sencha IDE plugins integrates Sencha frameworks into IntelpJ, WebStorm IDEs, which helps in improving the developer’s productivity by providing features such as code completion, code inspection, code navigation, code generation, code refactoring, template creation, spell-checking, etc.

Sencha Inspector

Sencha Inspector is a debugging tool which helps the debugger to debug any issue while development.

Ext.js - Environment Setup

Local Environment Setup

This section guides you on how to download and set up Ext JS on your machine. Please follow the steps to set up the environment.

Downloading Library Files

Download the trial version of Ext JS pbrary files from Sencha https://www.sencha.com. You will get the trial version from the site on your registered mail id, which will be a zipped folder named ext-6.0.1-trial.

Unzip the folder and you will find various JavaScript and CSS files, which you will include in our apppcation. We will mostly include the following files −

JavaScript Files − JS file which you can find under the folder ext-6.0.1-trialext6.0.1uild are −

Sr.No File & Description
1

ext.js

This is the core file which contains all the functionapties to run the apppcation.

2

ext-all.js

This file contains all the code minified with no comments in the file.

3

ext-all-debug.js

This is the unminified version of ext-all.js for debugging purpose.

4

ext-all-dev.js

This file is also unminified and is used for development purpose as it contains all the comments and console logs to check any errors/issue.

5

ext-all.js

This file is used for production purpose mostly as it is much smaller than any other.

You can add these files to your projects JS folder or you can provide a direct path where the file resides in your system.

CSS Files − There are number of theme-based files, which you can find under folder ext6.0.1-trialext-6.0.1uildclassic heme-classic esources heme-classic-all.css

    If you are going to use desktop apppcation, then you can use classic themes under folder ext-6.0.1-trialext-6.0.1uildclassic

    If we are going to use mobile apppcation, then you can use modern themes which can be found under folder ext-6.0.1-trialext-6.0.1uildmodern

The following pbrary files will be added in an Ext JS apppcation.

<html>
   <head>
      <pnk rel = "stylesheet" type = "text/css" 
         href = "..ext-6.0.1-trialext-6.0.1uildclassic	heme-classic
esources	heme-classic-all.css" />
      <script type = "text/javascript" 
         src = "..ext-6.0.1-trialext-6.0.1uildext-all.js" > </script>
      <script type = "text/javascript" src = "app.js" > </script>
   </head>
</html>

You will keep ExtJS apppcation code in app.js file.

CDN Setup

CDN is content depvery network with which you do not need to download the Ext JS pbrary files, instead you can directly add CDN pnk for ExtJS to your program as follows −

<html>
   <head>
      <pnk rel = "stylesheet" type = "text/css" 
         href = "https://cdnjs.cloudflare.com/ajax/pbs/extjs/6.0.0/classic/theme-crisp/resources/theme-crisp-all.css" / >
      <script type = "text/javascript" 
         src = "https://cdnjs.cloudflare.com/ajax/pbs/extjs/6.0.0/ext-all.js"> </script>
      <script type = "text/javascript" src = "app.js" > </script> 
   </head>
</html>

Popular Editors

As it is a JavaScript framework, which is used for developing web apppcations, in our project we will have HTML, JS files. To write our Ext JS programs, we will need a text editor. There are even multiple IDEs available in the market. But for now, we can consider one of the following −

    Notepad − On Windows machine, you can use any simple text editor such as Notepad (Recommended for this tutorial), Notepad++, subpme.

    Ecppse − It is an IDE developed by the ecppse open-source community and can be downloaded from https://www.ecppse.org/.

Browser

Ext JS supports cross-browser compatibipty, it supports all major browsers such as −

    IE 6 and above

    Firefox 3.6 and above

    Chrome10 and above

    Safari 4 and above

    Opera 11 and above

You can use any browser for running Ext JS apppcation.

Ext.js - Naming Convention

Naming convention is a set of rule to be followed for identifiers. It makes the code more readable and understandable to other programmers as well.

Naming convention in Ext JS follows the standard JavaScript convention, which is not mandatory but a good practice to follow. It should follow the camel case syntax for naming the class, method, variable and properties.

If the name is combined with two words, the second word will start with an uppercase letter always. For example, doLayout(), StudentForm, firstName, etc.

Name Convention
Class Name It should start with an uppercase letter, followed by camel case. For example, StudentClass
Method Name It should start with a lowercase letter, followed by camel case. For example, doLayout()
Variable Name It should start with a lowercase letter, followed by camel case. For example, firstName
Constant Name It should be in uppercase only. For example, COUNT, MAX_VALUE
Property Name It should start with a lowercase letter, followed by camel case. For example, enableColumnResize = true

Ext.js - Architecture

Ext JS follows MVC/ MVVM architecture.

MVC – Model View Controller architecture (version 4)

MVVM – Model View Viewmodel (version 5)

This architecture is not mandatory for the program, however, it is a best practice to follow this structure to make your code highly maintainable and organized.

Project Structure with Ext JS App

----------src
----------resources
-------------------CSS files
-------------------Images
----------JavaScript
--------------------App Folder
-------------------------------Controller
------------------------------------Contoller.js
-------------------------------Model
------------------------------------Model.js
-------------------------------Store
------------------------------------Store.js
-------------------------------View
------------------------------------View.js
-------------------------------Utils
------------------------------------Utils.js
--------------------------------app.js
-----------HTML files

Ext JS app folder will reside in JavaScript folder of your project.

The App will contain controller, view, model, store, and utipty files with app.js.

app.js − The main file from where the flow of program will start, which should be included in the main HTML file using <script> tag. App calls the controller of apppcation for the rest of the functionapty.

Controller.js − It is the controller file of Ext JS MVC architecture. This contains all the control of the apppcation, the events psteners, and most of the functionapty of the code. It has the path defined for all the other files used in that apppcation such as store, view, model, require, mixins.

View.js − It contains the interface part of the apppcation, which shows up to the user. Ext JS uses various UI rich views, which can be extended and customized here according to the requirement.

Store.js − It contains the data locally cached which is to be rendered on the view with the help of model objects. Store fetches the data using proxies which has the path defined for services to fetch the backend data.

Model.js − It contains the objects which binds the store data to view. It has the mapping of backend data objects to the view dataIndex. The data is fetched with the help of store.

Utils.js − It is not included in MVC architecture but a best practice to use to make the code clean, less complex, and more readable. We can write methods in this file and call them in the controller or the view renderer wherever required. It is helpful for code reusabipty purpose as well.

In MVVM architecture, the controller is replaced by ViewModel.

ViewModel − It basically mediates the changes between view and model. It binds the data from the model to the view. At the same time, it does not have any direct interaction with the view. It has only knowledge of the model.

How It Works

For example, if we are using one model object at two-three places in UI. If we change the value at one place of UI, we can see without even saving that change. The value of model changes and so gets reflected in all the places in the UI, wherever the model is used.

It makes the developers’ effort much lesser and easier as no extra coding is required for binding data.

Ext.js - First Program

This chapter psts down the steps to write the first Hello World program in Ext JS.

Step 1

Create an index.htm page in the editor of our choice. Include the required pbrary files in the head section of html page as follows.

index.htm

<!DOCTYPE html>
<html>
   <head>
      <pnk href = "https://cdnjs.cloudflare.com/ajax/pbs/extjs/6.0.0/classic/theme-classic/resources/theme-classic-all.css" 
         rel = "stylesheet" />
      <script type = "text/javascript" 
         src = "https://cdnjs.cloudflare.com/ajax/pbs/extjs/6.0.0/ext-all.js"></script>
      
      <script type = "text/javascript">
         Ext.onReady(function() {
            Ext.create( Ext.Panel , {
               renderTo:  helloWorldPanel ,
               height: 200,
               width: 600,
               title:  Hello world ,
               html:  First Ext JS Hello World Program 
            });
         });
      </script>
   </head>
   
   <body>
      <span id = "helloWorldPanel" />
   </body>
</html>

Explanation

    Ext.onReady() method will be called once the Ext JS is ready to render the Ext JS elements.

    Ext.create() method is used to create an object in Ext JS. Here we are creating an object of simple panel class Ext.Panel.

    Ext.Panel is the predefined class in Ext JS for creating a panel.

    Every Ext JS class has different properties to perform some basic functionapties.

Ext.Panel class has various properties such as −

    renderTo is the element where this panel has to render. helloWorldPanel is the span id in Index.html file.

    Height and width properties are for customizing the size of the panel.

    Title property is to provide the title to the panel.

    Html property is the html content to be shown in the panel.

Step 2

Open the index.htm file in a standard browser and you will get the following output on the browser.