Extjs Tutorial
Extjs Tutorial
Extjs Tutorial
Audience
This tutorial has been prepared for beginners to help them understand the concepts of
ExtJS to build dynamic web UI.
Prerequisites
For this tutorial, the reader should have prior knowledge of HTML, CSS, and JavaScript
coding. It would be helpful if the reader knows the concepts of object-oriented
programming and has a general idea on creating web applications.
Try the following example using the Try it option available at the top right corner of the
following sample code box −
<!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: 100,
i
width: 200,
title: 'Hello world',
html: 'First Ext JS Hello World Program'
});
});
</script>
</head>
<body>
<div id="helloWorldPanel"></div>
</body>
</html>
All the content and graphics published in this e-book are the property of Tutorials Point (I)
Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish
any contents or a part of contents of this e-book in any manner without written consent
of the publisher.
We strive to update the contents of our website and tutorials as timely and as precisely as
possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt.
Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our
website or its contents including this tutorial. If you discover any errors on our website or
in this tutorial, please notify us at contact@tutorialspoint.com
ii
Table of Contents
About the Tutorial .................................................................................................................................... i
Audience .................................................................................................................................................. i
Prerequisites ............................................................................................................................................ i
History .................................................................................................................................................... 1
Features .................................................................................................................................................. 2
Benefits ................................................................................................................................................... 2
Limitations .............................................................................................................................................. 2
Tools ....................................................................................................................................................... 3
iii
Container Inside Container .................................................................................................................... 18
Auto Layout........................................................................................................................................... 36
Table Layout.......................................................................................................................................... 45
Grid ....................................................................................................................................................... 52
Form...................................................................................................................................................... 56
iv
Yes NO Cancel Box ................................................................................................................................ 72
Chart ..................................................................................................................................................... 74
Tooltip................................................................................................................................................... 85
Window ................................................................................................................................................ 86
v
14. EXT.JS ─ FONTS ................................................................................................................ 121
vi
1. 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.
7
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.
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.
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.
Limitations
The size of the library is large, around 500 KB, which makes initial loading time more
and makes application slow.
According to general public license policy, it is free for open source applications but
paid for commercial applications.
8
Sometimes for loading even simple things require few lines of coding, which is simpler
in plain html or JQuery.
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 Inspector
Sencha Inspector is a debugging tool which helps the debugger to debug any issue while
development.
9
2. EXT.JS ─ ENVIRONMENT SETUP
Try the following example using Try it option available at the top right corner of the following
sample code box.
<!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: 100,
width: 200,
title: 'Hello world',
html: 'First Ext JS Hello World Program'
});
});
</script>
</head>
<body>
<div id="helloWorldPanel"></div>
</body>
</html>
10
For most of the examples given in this tutorial, you will find a Try It option in our website
code sections at the top right corner that will take you to the online compiler. Make use of it
and enjoy your learning.
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-trial\ext-6.0.1\build
are:
File Description
ext.js This is the core file which contains all the functionalities to run the application.
ext-all.js This file contains all the code minified with no comments in the file.
This file is also unminified and is used for development purpose as it contains all the
ext-all-dev.js
comments and console logs to check any errors/issue .
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 \ext-
6.0.1-trial\ext-6.0.1\build\classic\theme-classic\resources\theme-classic-all.css
If you are going to use desktop application, then you can use classic themes under
folder \ext-6.0.1-trial\ext-6.0.1\build\classic
11
If we are going to use mobile application, then you can use modern themes which can
be found under folder \ext-6.0.1-trial\ext-6.0.1\build\modern
<html>
<head>
<link rel = "stylesheet" type ="text/css" href= "..\ext-6.0.1-trial\ext-
6.0.1\build\classic\theme-classic\resources\theme-classic-all.css" />
<script type ="text/javascript" src = "..\ext-6.0.1-trial\ext-
6.0.1\build\ext-all.js" > </script>
<script type ="text/javascript" src = "app.js" > </script>
</head>
</html>
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.
12
Eclipse: It is an IDE developed by the eclipse open-source community and can be
downloaded from http://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
13
3. 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 It should start with a lowercase letter, followed by camel case. For example, doLayout()
Name
Variable It should start with a lowercase letter, followed by camel case. For example, firstName
Name
It should start with a lowercase letter, followed by camel case. For example,
Property
enableColumnResize = true
Name
14
4. EXT.JS ─ ARCHITECTURE
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.
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.
15
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.
16
End of ebook preview
If you liked what you saw…
Buy it from our store @ https://store.tutorialspoint.com
17