Ext.js – Quick Guide


Ext.js – Quick Guide


”;


Ext.js – Overview

Ext JS is a popular JavaScript framework which provides rich UI for building web applications with cross-browser functionality. Ext JS is basically used for creating desktop applications. 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 applications.

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 application 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 utility classes, which is an extension of YUI. He named the library 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 application with limited features. This version doesn’t have backward compatibility 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 list view but at the cost of speed. It had backward compatibility 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 application.

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 ability 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 application) and Sencha Touch (for mobile application) framework.

Features

Following are the highlighted features of Ext JS.

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

  • Code compatibility 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 client-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 application development. Ext JS provides the tools necessary to build robust applications for desktop and tablets.

  • Streamlines 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 application development.

  • Empowers the teams to create apps with a compelling 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 library is large, around 500 KB, which makes initial loading time more and makes application slow.

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

  • According to general public license policy, it is free for open source applications but paid for commercial applications.

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

  • Need quite experienced developer for developing Ext JS applications.

Tools

Following are the tools provided by Sencha used for Ext JS application 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 IntelliJ, 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 library 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 application. We will mostly include the following files −

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

Sr.No File & Description
1

ext.js

This is the core file which contains all the functionalities to run the application.

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.1buildclassictheme-classicresourcestheme-classic-all.css

  • If you are going to use desktop application, then you can use classic themes under folder ext-6.0.1-trialext-6.0.1buildclassic

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

The following library files will be added in an Ext JS application.

<html>
   <head>
      <link rel = "stylesheet" type = "text/css" 
         href = "..ext-6.0.1-trialext-6.0.1buildclassictheme-classicresourcestheme-classic-all.css" />
      <script type = "text/javascript" 
         src = "..ext-6.0.1-trialext-6.0.1buildext-all.js" > </script>
      <script type = "text/javascript" src = "app.js" > </script>
   </head>
</html>

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

CDN Setup

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

<html>
   <head>
      <link rel = "stylesheet" type = "text/css" 
         href = "https://cdnjs.cloudflare.com/ajax/libs/extjs/6.0.0/classic/theme-crisp/resources/theme-crisp-all.css" / >
      <script type = "text/javascript" 
         src = "https://cdnjs.cloudflare.com/ajax/libs/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 applications, 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++, sublime.

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

Browser

Ext JS supports cross-browser compatibility, 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 application.

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 utility 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 application for the rest of the functionality.

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

View.js − It contains the interface part of the application, 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 reusability 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 lists 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 library files in the head section of html page as follows.

index.htm

<!DOCTYPE html>
<html>
   <head>
      <link href = "https://cdnjs.cloudflare.com/ajax/libs/extjs/6.0.0/classic/theme-classic/resources/theme-classic-all.css" 
         rel = "stylesheet" />
      <script type = "text/javascript" 
         src = "https://cdnjs.cloudflare.com/ajax/libs/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>
      <div 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 functionalities.

Ext.Panel class has various properties such as −

  • renderTo is the element where this panel has to render. ”helloWorldPanel” is the div 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.