Ext.js - Methods


Advertisements

Following are a few inbuilt functions, which are heavily used in Ext JS.

Ext.is Class

This class checks the platform you are using, whether it is a phone or a desktop, a mac or Windows operating system. These are the following methods related to Ext.is class.

Sr.No Methods & Description
1

Ext.is.Platforms

This function returns the platform available for this version.

For example, when you run the following function, it returns something like this −

[Object { property = "platform", regex = RegExp, identity = "iPhone"}, 
Object { property = "platform", regex = RegExp, identity = "iPod"}, 
Object { property = "userAgent", regex = RegExp, identity = "iPad"}, 
Object { property = "userAgent", regex = RegExp, identity = "Blackberry"}, 
Object { property = "userAgent", regex = RegExp, identity = "Android"}, 
Object { property = "platform", regex = RegExp, identity = "Mac"}, 
Object { property = "platform", regex = RegExp, identity = "Windows"}, 
Object { property = "platform", regex = RegExp, identity = "Linux"}]
2

Ext.is.Android

This function will return true, if you are using Android operating system, else it returns false.

3

Ext.is.Desktop

This function will return true, if you are using a desktop for the application, else it returns false.

4

Ext.is.Phone

This function will return true, if you are using a mobile, else it returns false.

5

Ext.is.iPhone

This function will return true if you are using iPhone, else it returns false.

6

Ext.is.iPod

This function will return true, if you are using iPod, else it returns false.

7

Ext.is.iPad

This function will return true, if you are using an iPad, else it returns false.

8

Ext.is.Windows

This function will return true, if you are using Windows operating system, else it returns false.

9

Ext.is.Linux

This function will return true, if you are using Linux operating system, else it returns false.

10

Ext.is.Blackberry

This function will return true, if you are using Blackberry, else it returns false.

11

Ext.is.Mac

This function will return true, if you are using Mac operating system, else it returns false.

Ext.supports Class

As the name indicates, this class provides information if the feature is supported by the current environment of the browser/device or not.

Sr.No Methods & Description
1

Ext.supports.History

It checks if the device supports HTML 5 history as window.history or not. If the device supports history, then it returns true, else false.

2

Ext.supports.GeoLocation

It checks if the device supports geolocation method or not. Internally it checks for navigator.geolocation method.

3

Ext.supports.Svg

It checks if the device supports HTML 5 feature scalable vector graphics (svg) method or not. Internally it checks for doc.createElementNS && !!doc.createElementNS( "http:/" + "/www.w3.org/2000/svg", "svg").createSVGRect.

4

Ext.supports.Canvas

It checks if the device supports HTML 5 feature canvas to draw method or not. Internally it checks for doc.createElement('canvas').getContext and returns a value based on the output of this method.

5

Ext.supports.Range

It checks if the browser supports document.createRange method or not.

Ext.String Class

Ext.String class has various methods to work with string data. The most used methods are encoding decoding, trim, toggle, urlAppend, etc.

Encoding Decoding function − These are the functions available in Ext.String class to encode and decode HTML values.

Sr.No Methods & Description
1

Ext.String.htmlEncode

This function is used to encode html value to make it parsable.

Example

Ext.String.htmlEncode("< p > Hello World < /p >"); 
Output - "&lt; p &gt; Hello World &lt; /p &gt;".
2

Ext.String.htmlDecode

This function is used to decode the encoded html value.

Example

Ext.String.htmlDecode("&lt; p &gt; Hello World &lt; /p &gt;");
Output -  "< p > Hello World < /p &gt"
3

Ext.String.trim

This function is to trim the unwanted space in the string.

Ext.String.trim('      hello      ');
Output – "hello"
4

Ext.String.urlAppend

This method is used to append a value in the URL string.

Example

Ext.String.urlAppend('https://www.google.com' , 'hello'); 
Output - "https://www.google.com?hello" 
Ext.String.urlAppend('https://www.google.com?index=1' , 'hello'); 
Output – "https://www.google.com?index=1&hello" 
5

Ext.String.toggle

This function is to toggle the values between two different values.

Example

var toggleString = 'ASC' 
toggleString = Ext.String.toggle(a, 'ASC', 'DESC');
Output – DESC as toggleString had value ASC. Now again, if we 
print the same we will get toggleString = “ASC” this time, as 
it had value 'DESC'. 
It is similar to ternary operator 
toggleString = ((toggleString =='ASC')? 'DESC' : 'ASC' );

Miscellaneous Methods

Sr.No Methods & Description
1

Ext.userAgent()

This function gives information about browser userAgent. UserAgent is to identify the browser and the operating system to the web server.

Example − If you are working in Mozilla, it returns something like: "mozilla/5.0 (windows nt 6.1; wow64; rv:43.0) gecko/20100101 firefox/43.0"

2

Version related function

This function returns the version of the browser currently in use, if the function is called related to IE. In Firefox browser, it returns 0. These functions are Ext.firefoxVersion, Ext.ieVersion, etc.

Example − If you are using Firefox browser and you call the method Ext.ieVersion for fetching the version of IE, then it returns 0. If you are using the same method in IE browser, then it will return the version you are using such as 8, 9, etc.

3

Ext.getVersion()

This function returns the current Ext JS version in use.

Example − If you call Ext.getVersion(), it returns an array of values such as version, short version, etc.

Ext.getVersion().version returns the current version of Ext JS used in the program, such as “4.2.2".

4

Browser related functions

These functions return Boolean values based on the browser in use. These methods are Ext.isIE, Ext.isIE6, Ext.isFF06, and Ext.isChrome.

Example − If you are using Chrome browser, then the function Ext.isChrome will return true all, otherwise it will return false.

5

Ext.typeOf()

This function returns the datatype of the variable.

Example

var a = 5;   
var b  = 'hello'; 
Ext.typeOf(a); 
Output – Number 
Ext.typeOf(b);
Output - String
6

DataType related methods − These functions return boolean value based on the datatype of the variable

Example

var a = ['a', 'bc'];
var b = 'hello';
var c = 123;
var emptyVariable;
var definedVariable;
function extraFunction(){return true;}
Ext.isArray(a); //returns true
Ext.isString(b); //return true
Ext.isNumber(c); //return true
Ext.isEmpty(emptyVariable); //return true
Ext.isEmpty(b); //return false
Ext.isDefined(definedVariable); //return true
Ext.isfunction(extraFunction); //return true
Advertisements