Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Ext JS 3.0 Cookbook
Ext JS 3.0 Cookbook

Ext JS 3.0 Cookbook: Clear step-by-step recipes for building impressive rich internet applications using the Ext JS JavaScript library

eBook
€8.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Ext JS 3.0 Cookbook

Chapter 1. DOM and Data Types, the Ext JS Way

In this chapter, you will learn the following recipes:

  • Detecting browsers and platforms used by clients

  • Retrieving DOM nodes and elements

  • Acquiring references to Ext JS components

  • Running high-performance DOM queries

  • Encoding and decoding JSON

  • Encoding and decoding URL data

  • Determining the object type and converting empty references to a default value

  • Finding objects in an array and removing array items

  • Manipulating strings à la Ext JS

  • Effortless range checking for numbers

  • Formatting, parsing, and manipulating dates

  • Preventing naming conflicts and scoping non-global variables

  • Extending JavaScript objects, the Ext JS way

  • Adding features to the Ext JS classes

  • Building custom JavaScript classes that inherit the functionality of Ext JS

Introduction

In this chapter, you will learn how to accomplish tasks related to working with different browsers, platforms, the Document Object Model (DOM), and the Ext JS data types. You will also take in how to create custom data types that extend the functionality of the native Ext JS types.

Introduction


In this chapter, you will learn how to accomplish tasks related to working with different browsers, platforms, the Document Object Model (DOM), and the Ext JS data types. You will also take in how to create custom data types that extend the functionality of the native Ext JS types.

Detecting browsers and platforms used by clients


Although Ext JS is a cross-browser library, there are instances when your application needs to show a different behavior depending on the user's browser or platform. Browser and platform detection are very simple tasks with Ext JS, and this recipe shows how it's done.

How to do it...

You can detect various browsers and platforms used by your clients in the following way:

  • You can use Ext.isChrome to find out if the detected browser is Chrome:

    var browser = "";
    if (Ext.isChrome) {
    browser = "Hi! I'm the new kid on the block";
    }
    
  • The browsers such as Mozilla and Firefox that use the Gecko rendering engine are detected with Ext.isGecko, Ext.isGecko2, and Ext.isGecko3:

    if (Ext.isGecko) {
    browser = "Gecko";
    }
    if (Ext.isGecko2) {
    browser = "Gecko2";
    }
    if (Ext.isGecko3) {
    browser = "We like Firefox!";
    }
    
  • The Internet Explorer versions are flagged by Ext.isIE, Ext.isIE6, Ext.isIE7, and Ext.isIE8:

    if (Ext.isIE) {
    browser = "IE";
    }
    if (Ext.isIE6) {
    browser = "Get a decent browser, now!";
    }
    if (Ext.isIE7) {
    browser = "IE7";
    }
    if (Ext.isIE8) {
    browser = "IE8";
    }
    
  • Opera is detected with Ext.isOpera:

    if (Ext.isOpera) {
    browser = "Opera";
    }
    
  • And finally, Safari is detected with Ext.isSafari, Ext.isSafari2, Ext.isSafari3, and Ext.isSafari4:

    if (Ext.isSafari) {
    browser = "Safari";
    }
    if (Ext.isSafari2) {
    browser = "Safari2";
    }
    if (Ext.isSafari3) {
    browser = "Safari3";
    }
    if (Ext.isSafari4) {
    browser = "Safari4";
    }
    
  • When it comes to platform detection, Adobe's Air is detected with Ext.isAir:

    var platform = "";
    if (Ext.isAir) {
    platform = "Air";
    }
    
  • Linux is detected withExt.isLinux:

    if (Ext.isLinux) {
    platform = "Linux";
    }
    
  • Mac OS is detected with Ext.isMac:

    if (Ext.isMac) {
    platform = "Mac";
    }
    
  • Windows is detected with Ext.isWindows:

    if (Ext.isWindows) {
    platform = "Windows ";
    }
    

How it works...

As you can imagine, the values for Ext JS's browser and platform type flags are all obtained from parsing the value of the userAgent property of the JavaScript navigator object.

There's more...

Use this recipe when you need to alter the features or behavior of your application depending on the browser or platform being used. For example, depending on the platform used, you can provide Mac or Windows versions of a browser plugin; or you can account for rendering differences of various browsers when positioning DOM elements.

Retrieving DOM nodes and elements


Web development involves hefty doses of DOM manipulation. This recipe shows how you can use Ext JS to get a handle on any DOM element.

How to do it...

Using a div element as an example, you can get a handle to the div in the following way:

<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" 
href="../ext/css/ext-all.css"/>
<script type="text/javascript" src="../ext/ext-base.js"></script>
<script type="text/javascript" 
src="../ext/ext-all-debug.js"></script>
<script type="text/javascript"> Ext.BLANK_IMAGE_URL = '../ext/images/default/s.gif';
Ext.onReady(function() {
var firstDiv = Ext.get("div-1");
Ext.Msg.alert('Using Ext.get(el)', firstDiv.id);
});
</script>
</head>
<body>
<div id="div-1">This is the first div</div>
</body>
</html>

How it works...

The previous code uses Ext.get(element), a shorthand for Ext.Element.get(element), to acquire a reference to a div element in the document. You can use this function to retrieve references that encapsulate DOM elements.

There's more...

The Ext.get(element) function uses simple caching to consistently return the same object. Note that Ext.get(element) does not retrieve Ext JS components. This is can be accomplished using Ext.getCmp(), explained in the next recipe.

See also...

  • The next recipe, Acquiring references to Ext JS components, explains how to obtain a reference to a previously created component.

  • The Running high performance DOM queries recipe, which is covered later in this chapter, teaches you how to run queries against the DOM using Ext JS.

Acquiring references to Ext JS components


As Ext JS is all about working with components, it's essential to learn how to acquire a reference to any component in your code. For example, this recipe shows how easy it is to reference a ComboBox component.

How to do it...

You can reference a ComboBox component as shown in the following code:

<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" 
href="../ext/css/ext-all.css"/>
<script type="text/javascript" src="../ext/ext-base.js"></script>
<script type="text/javascript" 
src="../ext/ext-all-debug.js"></script>
<script type="text/javascript"> 
Ext.BLANK_IMAGE_URL = '../ext/images/default/s.gif';
Ext.onReady(function() {
var colorsStore = new Ext.data.SimpleStore({
fields: ['name'],
data: [['Blue'],['Red'],['White']]
});
var combo = new Ext.form.ComboBox({
store: colorsStore,
displayField: 'name',
typeAhead: true,
mode: 'local',
forceSelection: true,
triggerAction: 'all',
emptyText: 'Select a color...',
selectOnFocus: true,
applyTo: 'colors-combo',
id: 'colors-combo'
});
// Get a reference to the combobox using Ext.getCmp(id).
var combo = Ext.getCmp("colors-combo");
// Using the reference to the combo, add a handler to the
//'select' event.
combo.on('select', function() {
Ext.Msg.alert('Using Ext.getCmp(id)', 
The selected color is ' + combo.getValue();
});
});
</script>
</head>
<body>
<input type="text" id="colors-combo"/>
</body>
</html>

How it works...

References to components are obtained using the Ext.getCmp(id) function, where id is the ID of the component. Keeping track of components is possible, thanks to the ComponentMgr class. It provides for easy registration, un-registration and retrieval, as well as notifications when components are added or removed.

There's more...

This method is particularly useful when explicit component references do not already exist in your code, for example when components are defined as part of the items collection of a container. (Think of a tab panel and its tabs, or a border layout and its contained panels.)

There are other DOM and component utilities provided by Ext JS:

  • Ext.getBody() returns the body of the document as an Ext.Element

  • Ext.getDoc() returns the current HTML document as an Ext.Element

  • Ext.getDom(id) returns the DOM node for the supplied ID, DOM node, or element

See also...

  • The Retrieving DOM nodes and elements recipe, covered earlier in this chapter, explains how to get a handle on any DOM element.

  • The next recipe, Running high-performance DOM queries, teaches you about running queries against the DOM.

Running high-performance DOM queries


Now you'll see how to run queries against the DOM using Ext JS—a must-have when you need to manipulate or perform actions on multiple, related DOM elements. The examples show how to reference all the div elements in a document, obtain all the elements with a CSS class name msg, and iterate over the options of a select element.

How to do it...

The following code snippets are examples of how to run high-performance queries against the DOM using Ext JS:

  • When you need to retrieve the elements that match the div selector to find the div elements in the document, use the following code snippet:

    Ext.onReady(function() {
    // Get all the div elements.
    var nodes = Ext.query('div');
    Ext.each(nodes, function(item, index, allItems) {
    document.write(index + '<br/>');
    });
    });
    
  • When you need to reference the elements with the class name msg, use the following code snippet:

    var msgLinks = Ext.query('.msg');
    Ext.each(msgLinks, function(item,index) {
    // Do something with the element here.
    });
    
  • When you want to iterate over the options of a select element, use the following code snippet:

    var select = Ext.get('countries-select');
    Ext.each(select.options, function(item,index) {
    // Do something with the item here.
    });
    

How it works...

The previous examples use Ext.query(path, [root]), a shorthand of Ext.DomQuery.select(path, [root]), to retrieve an array of DOM nodes that match a given selector.

There's more...

DomQuery provides high-performance selector/XPath processing by compiling queries into reusable functions. It works on HTML and XML documents, supports most of the CSS3 selector's specification as well as some custom selectors and basic XPath, and allows you to plug new pseudo classes and matchers.

See also...

  • The Retrieving DOM nodes and elements recipe, covered earlier in this chapter, shows how you can use Ext JS to get a handle on any DOM element.

  • The Acquiring references to Ext JS components recipe, covered earlier in this chapter, explains how to acquire a reference to any component in your code.

Encoding and decoding JSON


Converting JavaScript and Ext JS objects to JSON, and converting JSON data back to JavaScript objects is easily achievable with Ext JS. For example, here's how to JSON-encode an array and how to rebuild the array from its JSON representation:

Note

JavaScript Object Notation (JSON) is a lightweight text format where an object is represented with an unordered set of name/value pairs and an array with an ordered collection of values.

JSON is completely language independent, easy for humans to read and write, and easy for machines to parse and generate. These properties make JSON an ideal data-interchange format.

Find out more about JSON at www.json.org.

How to do it...

Let's encode an array of colors using the following steps:

  1. 1. Create an array called colorsArray:

    var colorsArray = new Array();
    
  2. 2. Put some values in the array:

    colorsArray[0] = 'Blue';
    colorsArray[1] = 'Red';
    colorsArray[2] = 'White';
    
  3. 3. Now, convert to JSON:

    var colorsJson = Ext.encode(colorsArray);
    

    The value of the colorsJson variable should be the string ["Blue","Red","White"] string

  4. 4. Let's re-create the array based on its JSON string. Take the JSON representation of colorsArray:

    var colorsJson = '["Blue","Red","White"]';
    
  5. 5. Parse the JSON and rebuild the array:

    var colorsArray = Ext.decode(colorsJson);
    

After this, colorsArray contains the colors data: colorsArray[0] is 'Blue', colorsArray[1] is 'Red', and colorsArray[2] is 'White'.

How it works...

To obtain a JSON representation of an array, object, or other value, pass the value to Ext.util.JSON.encode(object). You can also use the shorthand, Ext.encode(object).

You can parse a JSON string by using Ext.util.JSON.decode(json), or its shorthand Ext.decode(json).

While decoding JSON involves simply calling the JavaScript eval(String) function, the encoding process is more complicated and requires different implementations depending on the data type being encoded. Internally, the encode(object) function calls specialized encoding functions for arrays, dates, Boolean values, strings, and other types.

You can also set the Ext.USE_NATIVE_JSON property to true, which will cause calls to encode(object) and decode(json) to use the browser's native JSON handling features. This option is turned off by default. If you turn it on, beware that native JSON methods will not work on objects that have functions, and that property names should be quoted in order for the data to be correctly decoded.

There's more...

JSON encoding and decoding is a pillar of modern web development, given the role of JSON—a language-independent, data-interchange format—in facilitating communications between the client-side and server-side of web applications. For instance, you can expect to find JSON manipulation when your application needs to send data to the server, as well as when the application needs to dynamically create objects from server-supplied data.

See also...

  • The next recipe, Encoding and decoding URL data, shows how to do two-way conversion between objects and URL data.

Encoding and decoding URL data


Two-way conversion between objects and URL data is a challenge that Ext JS can help with. Let's examine how a JavaScript object can be encoded for transmission through the URL query string, as well as how information contained in a URL can be used to build a JavaScript object.

How to do it...

The following steps will guide you through the process of encoding and decoding URL data:

  1. 1. Take a selectedColors object as the data to be passed in a URL:

    var selectedColors = {color1:'Blue', color2:'Red', color3:'White'};
    
  2. 2. Convert the object to URL data like this:

    var encodedUrl = Ext.urlEncode(selectedColors);
    // encodedUrl is an encoded URL query string:
    //color1=Blue&color2=Red&color3=White.
    
  3. 3. Now, a URL can be built using the data just created. For example, http://MyGreatApp/SetSelectedColors?color1=Blue&color2=Red&color3=White.

  4. 4. You can easily create objects from the encoded URL. Assuming we obtained the data from the URL we used above (http://MyGreatApp/SetSelectedColors?color1=Blue&color2=Red&color3=White), obtain the URL data like this:

    encodedUrl = location.search;
    
  5. 5. Re-create the selectedColors object as follows:

    var selectedColors = Ext.urlDecode(encodedUrl); 
    // Now the value of selectedColors' color1 property is 'Blue',
    // color2's value is 'Red' and color3's value is 'White'.
    

How it works...

Ext.urlEncode(object) and Ext.urlDecode(string, overwrite) provide object serialization to URL data and URL data deserialization to objects respectively. Encoding is accomplished by creating the URL query string's key-value pairs based on each object property, or array value passed to the encoding function. Decoding is accomplished by creating an object with a property for each key-value pair that exists in the URL's query string.

There's more...

You can use this recipe when your application needs to send information to the server via AJAX or standard HTTP requests, as well as when you need to use the URL's query string to feed the application data that can later be converted to JavaScript objects.

See also...

  • The Encoding and decoding JSON recipe, covered earlier in this chapter, explains how to convert JavaScript objects to JSON and how to convert JSON to JavaScript objects.

Determining the object type and converting empty references to a default value


This recipe teaches you how to determine the types of different objects using the facilities of Ext JS, as well as a simple method that can be used to initialize empty references with a default value.

How to do it...

You can determine the types of different objects in the following way:

  1. 1. Create some dummy data structures:

    var colorsArray = new Array();
    colorsArray[0] = 'Blue';
    colorsArray[1] = 'Red';
    colorsArray[2] = 'White';
    var colorsObject = { color1: 'Blue', color2: 'Red', color3: 'White' };
    var aNumber = 1;
    var aString = '1';
    var sample;
    var empty;
    
  2. 2. Check the types of our variables:

    var colorsArrayType = Ext.type(colorsArray);
    // colorsArrayType's value is "array".
    var isArray = Ext.isArray(colorsArray);
    // isArray is true
    var colorsObjectType = Ext.type(colorsObject);
    // colorsObjectType's value is "object".
    var isArray = Ext.isArray(colorsObject);
    // isArray is false
    var number = Ext.num(aNumber, 0);
    // number is 1.
    number = Ext.num(aString, 0);
    // Since aString is not numeric, the supplied
    // default value (0) will be returned.
    var defined = Ext.util.Format.undef(sample);
    // defined is an empty string
    sample = "sample is now defined";
    defined = Ext.util.Format.undef(sample);
    // defined is now "sample is now defined".
    var notEmpty = Ext.value(empty, 'defaultValue', false);
    // notEmpty is 'defaultValue'
    

How it works...

The Ext.type(object) function is capable of detecting elements, objects, text nodes, whitespaces, functions, arrays, regular expressions, numbers, and node lists.

As its name indicates, Ext.isArray(object) simply checks whether the passed object is a JavaScript array. Ext.num(value, defaultValue), in turn, does a numeric type check on the passed value and returns the default value when the argument is not numeric.

Ext.util.Format.undef(value) is a very useful function when you need to test for undefined values. It returns either the supplied argument or an empty string if the argument is undefined.

Ext.value(value, defaultValue, allowBlank) also allows you to specify a default value when the value being tested is undefined.

Finding objects in an array and removing array items


The main task in this recipe is to find out whether an arbitrary object exists in an array. A way to remove objects from the array is also explored.

How to do it...

The following steps illustrate how you can perform object existence tests and object removal in an array:

  1. 1. Create a sample array as follows:

    var colorsArray = new Array();
    colorsArray[0] = 'Blue';
    colorsArray[1] = 'Red';
    colorsArray[2] = 'White';
    
  2. 2. Determine whether an object exists in an array by trying to find its position in the array:

    var position = colorsArray.indexOf('White');
    // postition is 2, the index of 'White' in the array.
    position = colorsArray.indexOf('Brown');
    // 'Brown' does not exist in the array,
    // position is -1.
    
  3. 3. Remove one of the objects from the array:

    colorsArray.remove('Blue');
    position = colorsArray.indexOf('Blue');
    // 'Blue' does not exist anymore,
    // position is -1.
    

How it works...

Ext JS augments the native Array class with Array.indexOf(object) and Array.remove(object). While indexOf(object) works by examining each array element until it finds one that matches the supplied argument, remove(object) uses the native Array.splice(index, howmany, element1,....., elementX) function to remove the supplied argument from the array.

Manipulating strings à la Ext JS


String manipulation has always been a challenging area in JavaScript. Here, you will learn how to escape special characters, trim, pad, format, truncate, and change the case of your strings with the help of the utilities of Ext JS.

How to do it...

You can manipulate strings as shown in the following steps:

  1. 1. Create your sample values as shown here:

    var needsEscape = "ExtJS's String Class will escape this";
    var needsTrimming = " Needs trimming ";
    var cls = 'color-class'
    var color = 'Blue';
    var sort = 'ASC';
    var sample = "some text";
    var longText = "This text should be truncated, it's really long.";
    var withScript = 'Some text<script type="text/javascript">var color = "Blue";<\/script>';
    var longText = "Only a part of this text is needed.";
    var multiLineText = "One line\nAnother line\nYet another line";
    var money = 29.99;
    var sample1 = '22';
    var sample2 = '550';
    var sample3 = '1500';
    
  2. 2. Now, let's use the string manipulation functions:

    var escaped = String.escape(needsEscape);
    document.write(escaped + '<br/>');
    // The escaped string is "ExtJS\'s String Class will escape this".
    var trimmed = needsTrimming.trim();
    document.write(trimmed + '<br/>');
    // the trimmed string is "Needs trimming"
    var formatted = String.format('<span class="{0}">{1}</span>', cls, color);
    document.write(formatted + '<br/>');
    // formatted is '<div class="color-class">Color</div>'
    sort = sort.toggle('ASC', 'DESC');
    document.write(sort + '<br/>');
    // instead of conditional logic:
    //sort = (sort == 'ASC' ? 'DESC' : 'ASC');
    var converted = Ext.util.Format.uppercase(sample);
    document.write(converted + '<br/>');
    // converted is now "SOME TEXT".
    sample = "SOME TEXT";
    converted = Ext.util.Format.lowercase(sample);
    // converted is now "some text".
    document.write(converted + '<br/>');
    sample = "some text";
    converted = Ext.util.Format.capitalize(sample);
    document.write(converted + '<br/>');
    // converted is now "Some text".
    var truncated = Ext.util.Format.ellipsis(longText, 20);
    document.write(truncated + '<br/>');
    // truncated is "This text should ...".
    // Removing script tags
    var noScript = Ext.util.Format.stripScripts(withScript);
    document.write(noScript + '<br/>');
    // noScript is "Some text".
    // Returning a portion of a string
    var subString = Ext.util.Format.substr(longText, 0, 11);
    document.write(subString + '<br/>');
    // subString is "Only a part".
    // Converting newline characters to the html tag <br/>
    var html = Ext.util.Format.nl2br(multiLineText);
    document.write(html + '<br/>');
    // html is
    // One line
    // Another line
    // Yet another line
    var usCurrency = Ext.util.Format.usMoney(money);
    document.write(usCurrency + '<br/>');
    // usCurrency is $29.99
    // Normalizing strings
    var normalized1 = String.leftPad(sample1, 4, '0');
    // normalized1 is '0022'
    var normalized2 = String.leftPad(sample2, 4, '0');
    // normalized3 is '0550';
    var normalized3 = String.leftPad(sample3, 4, '0');
    // normalized2 is '1500'
    document.write(normalized1 + '<br/>');
    document.write(normalized2 + '<br/>');
    document.write(normalized3 + '<br/>');
    

How it works...

The useful functions escape(string), trim(), format(value, start, length), toggle(value1, value2), and leftPad(string, size, [char]) all belong to the Ext.String class, which is an extension of the JavaScript String object.

The rest of the functions mentioned in this recipe belong to the Ext.util.Format class. Format is a singleton class that contains reusable formatting functions. Other useful functions in Format are htmlEncode(string) and htmlDecode(string).

Effortless range checking for numbers


Now, you'll see how to use Ext JS in order to guarantee that a number falls within a certain range.

How to do it...

The following steps illustrate how to perform range checking on numeric values:

  1. 1. Create your sample numbers:

    var number1 = 30;
    var number2 = 75;
    
  2. 2. Check whether your numbers are within a range:

    var constrained = number1.constrain(25, 50);
    // constrained is 30 because number1 is
    // within the specified range
    constrained = number2.constrain(25, 50);
    // constrained is 50 because number2 is
    // greater than the max. value in the range
    

How it works...

Ext.Number is a one-function extension of the JavaScript Number object. The only function of Ext.Number is constrain(min, max), which simply uses methods of the Math JavaScript object to accomplish the range checks on the given number.

constrain: function(min, max) {
return Math.min(Math.max(this, min), max);
}

Formatting, parsing, and manipulating dates


Another area where the dynamic nature of JavaScript creates challenges is dates manipulation. This recipe covers formatting, conversion, and range checking for dates.

How to do it...

You can format, convert, and range check dates as show in the following steps:

  1. 1. Add the date patterns you will use to format dates in your code:

    Date.patterns = {
    ISO8601Long: "Y-m-d H:i:s",
    ISO8601Short: "Y-m-d",
    ShortDate: "n/j/Y",
    LongDate: "l, F d, Y",
    FullDateTime: "l, F d, Y g:i:s A",
    MonthDay: "F d",
    ShortTime: "g:i A",
    LongTime: "g:i:s A",
    SortableDateTime: "Y-m-d\\TH:i:s",
    UniversalSortableDateTime: "Y-m-d H:i:sO",
    YearMonth: "F, Y"
    };
    
  2. 2. Create a sample Date object:

    var now = new Date();
    
    
  3. 3. Format the date using the patterns:

    var ISO8601Long = now.format(Date.patterns.ISO8601Long);
    //ISO8601Long is similar to 2009-03-05 14:01:45
    var ISO8601Short = now.format(Date.patterns.ISO8601Short);
    //ISO8601Long is similar to 2009-03-05
    var ShortDate = now.format(Date.patterns.ShortDate);
    //ISO8601Long is similar to 3/5/2009
    var LongDate = now.format(Date.patterns.LongDate);
    //ISO8601Long is similar to Thursday, March 05, 2009
    var FullDateTime = now.format(Date.patterns.FullDateTime);
    //ISO8601Long is similar to Thursday, March 05, 2009 2:01:45 PM
    var MonthDay = now.format(Date.patterns.MonthDay);
    //ISO8601Long is similar to March 05
    var ShortTime = now.format(Date.patterns.ShortTime);
    //ISO8601Long is similar to 2:01 PM
    var LongTime = now.format(Date.patterns.LongTime);
    //ISO8601Long is similar to 2:01:45 PM
    var SortableDateTime = now.format(Date.patterns.SortableDateTime);
    //ISO8601Long is similar to 2009-03-05T14:01:45
    var UniversalSortableDateTime = now.format(Date.patterns.UniversalSortableDateTime);
    //ISO8601Long is similar to 2009-03-05 14:01:45-0500
    var YearMonth = now.format(Date.patterns.YearMonth);
    //ISO8601Long is similar to March, 2009
    
  4. 4. Create a variable to hold your parsed date:

    var aDate = new Date();
    
  5. 5. Convert a string to a date:

    aDate = Date.parseDate("March, 2009", Date.patterns.YearMonth);
    //aDate = Thu Mar 5 00:00:00 EST 2009
    aDate = Date.parseDate("2:01:45 PM", Date.patterns.LongTime);
    //aDate = Thu Mar 5 14:01:45 EST 2009
    aDate = Date.parseDate("2009-03-05", Date.patterns.ISO8601Short);
    //aDate = Thu Mar 5 00:00:00 EST 2009
    
  6. 6. For range checking, create range limits:

    var low = Date.parseDate("July, 2008", Date.patterns.YearMonth);
    var high = Date.parseDate("July, 2009", Date.patterns.YearMonth);
    
  7. 7. Check whether your date is in the range:

    var now = new Date();
    var inRange = now.between(low, high);
    // inRange is true
    

How it works...

Ext JS enhances the JavaScript Date object with the Ext.Date class, which provides a number of properties and functions that simplify your work with dates.

Regarding date formats, although there isn't a central repository of format patterns in Ext JS, the Ext JS API documentation provides the ones used in the previous example. In order for these formats to become available on the Date object, they should be copied into any script that is included after Date.js.

There's more...

Besides the functions in the examples above, Ext.Date allows you to do things such as:

  • Getting the numeric representation of the year

  • Getting the number of days in the current month

  • Determining the number of milliseconds between two dates

  • Getting the date of the first day of the month in which a date resides

  • Getting the first day of the current month

  • Getting the offset from GMT of the current date

  • Getting the date of the last day of the month in which a date resides

  • Getting the last day of the current month

  • Getting the month number for the given short/full month name

  • Getting the short day name for a given day number

  • Getting the short month name for a given month number

  • Determining if a date is in a leap year

Preventing naming conflicts and scoping non-global variables


Naming conflicts and scoping problems increase as applications gain size, and you start to work with multiple code files and modules. In Ext JS, you can resolve these issues by creating namespaces where you can logically organize your code.

How to do it…

The following steps will show how to create a namespace and "hide" local variables in it. These variables will not collide with similarly-named variables that are stored in other namespaces or have global scope:

  1. 1. Define a namespace for the variables that are not global:

    Ext.namespace('ExtJSCookbook.Samples');
    
  2. 2. Create a local variable and a global variable with the same name:

    Ext JSCookbook.Samples.var1 = 'var1 (local)';
    // ExtJSCookbook.Samples.var1 is limited to the ExtJSCookbook.Samples namespace
    var var1 = 'var1 (global)';
    // var1 is a global variable
    
  3. 3. Prevent name collisions by putting any custom types inside the namespace you created:

    // A custom type inside the Ext JSCookbook.Samples namespace
    ExtJSCookbook.Samples.Person = function() {
    return {
    firstName: '',
    lastName: '',
    show: function() {
    alert(this.firstName + ' ' + this.lastName);
    }
    }
    }
    var person1 = new Ext JSCookbook.Samples.Person();
    person1.firstName = 'Jorge';
    person1.lastName = 'Ramon';
    person1.show();
    

How it works…

Ext.namespace(namespace1, namespace2, namespace3,…) and its shorthand Ext.ns(…) allow you to create an arbitrary number of namespaces that you can use to scope variables and classes that are not global. For example, have a look at the following piece of code:

Ext.namespace('MyApplication', 'MyApplication.UI', 'MyApplication.Data', 'MyApplication.Services');

This namespace's definition above is equivalent to the following statements:

MyApplication = {};
MyApplication.UI = {};
MyApplication.Data = {};
MyApplication.Services = {};

Extending JavaScript objects, the Ext JS way


You can use Ext JS to enhance the native JavaScript classes by making your own functions appear as if they were members of these classes. This recipe uses the Array class as an example, explaining how to augment its features by adding a function that will allow an array to copy itself into another array.

How to do it…

Adding a new function to the Array class is shown in the following steps:

  1. 1. Use Ext JS to add a new function, copyTo(array, startIndex), to the Array class's prototype:

    Ext.applyIf(Array.prototype, {
    copyTo: function(dest, startIndex) {
    l = this.length;
    for (var i = 0; i < l; i++) {
    dest[startIndex + i] = this[i];
    }
    }
    })
    
  2. 2. Create a source array and a destination array in order to test the new function:

    var source = new Array();
    var destination = new Array();
    source[0] = '1';
    source[1] = '2';
    source[2] = '3';
    destination[0] = '4';
    destination[1] = '5';
    destination[2] = '6';
    destination[3] = '7';
    destination[4] = '8';
    destination[5] = '9';
    
  3. 3. Verify that the function is available in the Array class:

    var serialized = destination.toString();
    // serialized is "4,5,6,7,8,9"
    // Copy the source array, starting at index 2 of the destination
    source.copyTo(destination, 2);
    serialized = destination.toString();
    // serialized is "4,5,1,2,3,9"
    
    

How it works…

Ext.applyIf(object1, object2) copies all of the properties of object2 to object1, if they do not already exist. This effectively allows you to add new functionality to object1.

There's more…

If you want to add or replace an object's current properties, you can use Ext.apply(object1, object2). This function will copy the properties of object2 to object1, replacing the ones that object1 has already defined.

Adding features to the Ext JS classes


It is possible to add new functions to the Ext JS classes, as well as modify the behavior of the native functions. To illustrate this point, this recipe explains how you can modify the MixedCollection class so that it features a new function which allows items to be added only when they don't already exist in the collection.

How to do it...

The following example shows how to add a new function to the MixedCollection class:

  1. 1. Define the new addUnique(key, object) function within the MixedCollection class:

    // Add a function to the MixedCollection Class.
    Ext.override(Ext.util.MixedCollection, {
    addUnique: function(key, object) {
    if (this.indexOf(object) > -1) return;
    this.add(key, object);
    }
    });
    
  2. 2. Now, we can use the new feature here:

    Ext.onReady(function() {
    // Create our enhanced collection.
    var col = new Ext.util.MixedCollection();
    // Confirm that the same value cannot be added twice.
    col.add("key 1", "value 1");
    document.write("Original count: " + col.getCount() + "<br/>");
    // Use the added function to make sure duplicates are not
    //added.
    col.addUnique("key 2", "value 1");
    // Number of elements in the collection is still 1.
    document.write("Count after trying to add a duplicate: " + col.getCount() + "<br/>");
    });
    
    

How it works...

The magic in this recipe is achieved through the use of Ext.override(originalClass, overrides). This function adds a list of functions to the prototype of an existing class, replacing any existing methods with the same name:

override: function(origclass, overrides) {
if (overrides) {
var p = origclass.prototype;
Ext.apply(p, overrides);
if (Ext.isIE && overrides.toString != origclass.toString) {
p.toString = overrides.toString;
}
}
}

There's more...

Using Ext.override(originalClass, overrides), it is also possible to modify the behavior of a class's native functions.

Let's modify the add(key, object) function of the MixedCollection class so that only unique values can be added to the collection.

Use Ext.override(originalClass, overrides) to redefine the add function as shown in the following code:

Ext.override(Ext.util.MixedCollection, {
// The new add function, with the unique value check.
add: function(key, o) {
// The unique value check.
if (this.indexOf(o) > -1) return null;
//From this point, the code is the add function's original
//code.
if (arguments.length == 1) {
o = arguments[0];
key = this.getKey(o);
}
if (typeof key == "undefined" || key === null) {
this.length++;
this.items.push(o);
this.keys.push(null);
} else {
var old = this.map[key];
if (old) {
return this.replace(key, o);
}
this.length++;
this.items.push(o);
this.map[key] = o;
this.keys.push(key);
}
this.fireEvent("add", this.length - 1, o, key);
return o;
}
});

Now, we can use the new behavior:

Ext.onReady(function() {
// Create our enhanced collection.
var col = new Ext.util.MixedCollection();
// Confirm that the same value cannot be added twice.
col.add("key 1", "value 1");
document.write("Original count: " + col.getCount() + "<br/>");
// Try to add a duplicate.
col.add("key 2", "value 1");
// Number of elements in the collection is still 1.
document.write("Count after trying to add a duplicate: " + col.getCount() + "<br/>");
});

See also...

  • The next recipe, Building custom JavaScript classes that inherit the functionality of Ext JS, explains how to incorporate Ext JS's features into your custom classes.

Building custom JavaScript classes that inherit the functionality of Ext JS


You can incorporate features of Ext JS into your own JavaScript classes. For example, the ObservableList class created in this recipe will use the features of the framework's Ext.util.Observable class to fire notifications when items are added, removed, or when the list is cleared. The list's interface will be as follows:

  • add(object): A function that inserts an item in the list and returns the position into which the item was inserted

  • insert(index, object): A function that inserts an item to the List at the specified index

  • item(index): A function that returns the element at the specified index

  • remove(object): A function to remove the first occurrence of a specific object

  • removeAt(index): A function in charge of removing the item at the specified index

  • each(fn, scope): A method that executes the specified function once for every item in the list

  • clear(): A function to remove all items from the list

  • add: An event signaling that an element was added

  • remove: An event notifying that an element was removed

  • clear: An event signaling that the list was cleared

How to do it…

Let's proceed to build and test the ObservableList class as shown in the following steps:

  1. 1. Define the ObservableList class:

    Ext.namespace("Samples");
    Samples.ObservableList = function() {
    this.items = [];
    this.length = 0;
    // The events our custom class will expose.
    // The parent Class, Observable, will handle event publishing
    //for us.
    this.addEvents("add", "remove", "clear");
    Samples.ObservableList.superclass.constructor.call(this);
    };
    
  2. 2. Inherit the Observable class's functionality by establishing our class as an extension of Observable:

    Ext.extend(Samples.ObservableList, Ext.util.Observable, {
    //Disable having functions as items.
    allowFunctions: false,
    //Our Class members go here...
    });
    
    
  3. 3. Now, implement our class's interface:

    Ext.extend(Samples.ObservableList, Ext.util.Observable, {
    allowFunctions: false,
    //Adds an item to the list and
    //returns the position into which the new element was inserted.
    add: function(o) {
    this.items.push(o);
    this.length++;
    // Fire the add event, returning the position
    // into which the new element was inserted.
    pos = this.length - 1;
    this.fireEvent("add", pos);
    return pos;
    },
    // Inserts an item to the List at the specified index.
    insert: function(index, o) {
    //If the index is outside the list, insert the element at
    // the end of the list.
    if (index >= this.length) {
    return this.add(o);
    }
    this.length++;
    this.items.splice(index, 0, o);
    this.fireEvent("add", index);
    },
    // Removes all items from the list.
    clear: function() {
    this.length = 0;
    this.items = [];
    this.fireEvent("clear");
    },
    // Determines the index of a specific item in the list.
    indexOf: function(o) {
    return this.items.indexOf(o);
    },
    // Determines whether the List contains a specific value.
    contains: function(o) {
    return this.indexOf(o) != -1;
    },
    // Our enumerator function. Executes the specified function
    //once for every element in the list.
    each: function(fn, scope) {
    var items = [].concat(this.items); for (var i = 0, len = items.length; i < len; i++) {
    if (fn.call(scope || items[i], items[i], i, len) === false) {
    break;
    }
    }
    },
    custom JavaScript classescustom JavaScript classesbuilding// Removes the item at the specified index.
    removeAt: function(index) {
    if (index < this.length && index >= 0) {
    this.length--;
    var o = this.items[index];
    this.items.splice(index, 1);
    this.fireEvent("remove", o);
    }
    },
    // Removes the first occurrence of a specific object.
    remove: function(o) {
    this.removeAt(this.indexOf(o));
    },
    // Return the element at the specified index.
    item: function(index) {
    var item = this.items[index];
    return item;
    }
    });
    Samples.ObservableList.prototype.get = Samples.ObservableList.prototype.item;
    
  4. 4. It's time to test our class. Let's do it as follows:

    Ext.onReady(function() {
    list = new Samples.ObservableList();
    for (var i = 0; i < 15; i++) {
    pos = list.add("test " + i);
    }
    // Add handlers for the list's events.
    list.on("remove", function(o) {
    alert("Removed: " + o);
    });
    list.on("add", function(index) {
    alert("Added at position: " + index);
    });
    list.on("clear", function() {
    alert("List length is: " + list.length);
    });
    document.write("List length is " + list.length + "<br/>");
    // Insert an additional element and
    //check that the add event fires.
    var index = 2;
    list.insert(index, "A new item");
    document.write("Just inserted: " + list.item(index) + "<br/>");
    document.write("List length is: " + list.length + "<br/>");
    // Remove an item an verify that the remove event fires.
    index = 5;
    document.write("Removing item at position" + index + "<br/>");
    list.removeAt(index);
    document.write("List length after removal: " + list.length + "<br/>");
    document.write("Clearing list...<br/>");
    // Remove all items and check that the clear event fires.
    list.clear();
    document.write("List length after clear: " + list.length + "<br/>");
    });
    
    

How it works…

A powerful mechanism for extending classes is provided by Ext JS with Ext.extend(subclass, superclass, [overrides]). This function allows you to extend one class with another class and, optionally, to override the superclass's members.

Our example first defines the custom ObservableList class and passes its events to the parent, Ext.Observable. It then uses Ext.extend(subclass, superclass, [overrides]) not only to establish that the custom class implements Ext.Observable, but also to define the bulk of its own interface—the add(object), insert(index, object), clear(), indexOf(object), each(fn, scope), removeAt(index), remove(object), and item(index) functions.

Multiple versions of this approach are used by Ext JS to define its own class hierarchy. I encourage you to examine the source code of the library in order to get familiar with them.

See also…

  • The Adding features to the Ext JS classes recipe, covered earlier in this chapter, explains how to add new functions to the Ext JS classes

  • The A custom column layout recipe from Chapter 2 is an example of how to extend the native Ext JS layouts

  • The A three-panel application layout with one line of code recipe from Chapter 2 shows how to build a reusable Ext JS component that encapsulates a three-panel layout

Left arrow icon Right arrow icon

Key benefits

  • Master the Ext JS widgets and learn to create custom components to suit your needs
  • Build striking native and custom layouts, forms, grids, listviews, treeviews, charts, tab panels, menus, toolbars and much more for your real-world user interfaces
  • Packed with easy-to-follow examples to exercise all of the features of the Ext JS library
  • Part of Packt's Cookbook series: Each recipe is a carefully organized sequence of instructions to complete the task as efficiently as possible

Description

Using Ext JS you can easily build desktop-style interfaces in your web applications. Over 400,000 developers are working smarter with Ext JS and yet most of them fail to exercise all of the features that this powerful JavaScript library has to offer. Get to grips with all of the features that you would expect with this quick and easy-to-follow Ext JS Cookbook. This book provides clear instructions for getting the most out of Ext JS with and offers many exercises to build impressive rich internet applications. This cookbook shows techniques and "patterns" for building particular interface styles and features in Ext JS. Pick what you want and move ahead. It teaches you how to use all of the Ext JS widgets and components smartly, through practical examples and exercises. Native and custom layouts, forms, grids, listviews, treeviews, charts, tab panels, menus, toolbars, and many more components are covered in a multitude of examples.The book also looks at best practices on data storage, application architecture, code organization, presenting recipes for improving themóour cookbook provides expert information for people working with Ext JS.

Who is this book for?

The Ext JS Cookbook is for Ext JS users who want a book of useful techniques, with explanations, that they can refer to and adapt to their purposes. Developers who are already familiar with Ext JS will find practical guidance and numerous examples covering most of the library's features and components that can be used as a solid foundation to build upon when creating rich internet applications.

What you will learn

  • Work with different browsers, platforms, and the DOM, as well as determine and understand the different ExtJS data types
  • Create your own custom Ext JS data types as you extend their functionality
  • Build great-looking and friendly forms by using client and server-side field validation, form loading, submission, field customization, and layout techniques
  • Explore the different layouts provided by the Ext JS library as well as create your own, and understand their common uses
  • Display, edit, and group tabular data generated by the server using Grid Panels
  • Explore the advantages and the efficiency tradeoffs of widgets such as Combo boxes
  • Use the drag and drop features of the grid component, data editing with the new RowEditor Class, and the new lightweight ListView component
  • Explore multiple ways of displaying master-details relationships
  • Group components or information under the same container to build hierarchical views of information by using TabPanel components
  • Use patterns to build a solid and flexible application architecture and implement additional design patterns such as auto-saving form elements, component state management, and code modules to build robust and flexible applications with Ext JS
  • Build your own custom components on top of the Ext framework and enhance the custom components created by the Ext JS users community
Estimated delivery fee Deliver to Portugal

Premium delivery 7 - 10 business days

€17.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 20, 2009
Length: 376 pages
Edition : 1st
Language : English
ISBN-13 : 9781847198709
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Portugal

Premium delivery 7 - 10 business days

€17.95
(Includes tracking information)

Product Details

Publication date : Oct 20, 2009
Length: 376 pages
Edition : 1st
Language : English
ISBN-13 : 9781847198709
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 41.99
Ext JS 3.0 Cookbook
€41.99
Total 41.99 Stars icon
Banner background image

Table of Contents

10 Chapters
DOM and Data Types, the Ext JS Way Chevron down icon Chevron up icon
Laying Out a Rich User Interface Chevron down icon Chevron up icon
Load, Validate, and Submit Forms Chevron down icon Chevron up icon
Fun with Combo Boxes and Date Fields Chevron down icon Chevron up icon
Using Grid Panels to Display and Edit Tabular Data Chevron down icon Chevron up icon
More Applications of Grid and List Views Chevron down icon Chevron up icon
Keeping Tabs on Your Trees Chevron down icon Chevron up icon
Making Progress with Menus and Toolbars Chevron down icon Chevron up icon
Well-charted Territory Chevron down icon Chevron up icon
Patterns in Ext JS Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.7
(6 Ratings)
5 star 66.7%
4 star 33.3%
3 star 0%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




RandomUser2221 Dec 08, 2009
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I've been using ExtJS for the last year and have experienced the transition from version 2.0 to 3.0 and have been rather pleased with the results it has delivered for numerous web projects I've coded. After trying many other JS kits and frameworks including Jquery, Mootools, and several others I have generally settled on ExtJS to solve the layout and user interface parts of my applications because of its ease of use and flexible nature for expansion. The framework is an extension of the Yahoo javascript framework, otherwise known as YUI, but with many quality extensions. This book comes as a welcome guide to the general tasks that the framework will solve as well as some of the more unique and in-depth items that it can provide. Quite simply it's a book with over a hundred examples of all the best features of the ExtJS framework. The examples are well explained with detailed write-ups that are fun to read. The examples also have immediately usable code for dropping into place or modifying for your own needs. If you're interested in learning more about this amazing framework or are already acquainted and need a quick guide to expand your abilities, then this will be a good reference to own. Before I get going you can see the book here.The book starts out with an overview of the way that ExtJS handles DOM and data types, which is all very basic stuff but required understanding as well. It's a good start to understanding the base elements if you are a bit rusty. It's also a good chapter to see how ExtJS handles them since it might not be what you are used to if coming from another framework. After enough pages to answer most typical questions of that topic the book dives into the UI building aspects of the framework. This is where things get really good as I've always enjoyed how the framework builds UI for the web. You get examples for containers and positioning, accordion functionality, card and tab based windowing, column and table layouts, and the windowing functions for full browser UI building. I've used many of these features all in one layout and the results are a effective and efficient manner of data distribution and information organization for content driven sites. The book even covers dynamic building of UI elements, which comes in handy for a user interface that grows and changes with the needs of the user.After you build your UI you need methods to get content into the application and ways that the user can interact with the app. The book addresses these needs as well. Plenty of examples abound for all of the required manners that users will be using forms, date fields, combo boxes, remote data loading via JSON and XML, as well as covering grid panels and data tables. Of course it must be mentioned that there are numerous examples that discuss the AJAX features of ExtJS since this is one of it's major strengths and successes. If there's a way to use remote data calls via XML or JSON, it is covered in this book. We also get a nice run down of trees and tab data which is inevitably useful for many purposes. If you are interested in progress bars and customized progress circles the book covers those with over 20 pages of examples. Just before the topics are finished off Jorge covers the functions for building rich charts and graphs. Details involve static data display, remote data display, as well as auto-refresh of data for realtime charting. Patterns, class extensions, plugins, and 'keeping state' are the last topics of the book. They offer quality methods for customizing ExtJS with your own JS code and keeping the user's data consistent between sessions.Overall this is one of the best books I've read about ExtJS. It's as if the author took all of the items that I had to research over the last year of using the framework and put the solutions all into a nicely readable form with quality code examples that are explained in a useful manner. If you are looking for a book that touches upon the most common and some of the more esoteric options of the ExtJS framework but don't feel like scouring the online forums and hundreds of pages of documentation then this is the book for you. If you haven't already built your own code for the features that the chapters discuss then the examples given will save you time and get your projects up and running fast and efficiently.
Amazon Verified review Amazon
Art Nov 23, 2009
Full star icon Full star icon Full star icon Full star icon Full star icon 5
ExtJS 3.0 Cookbook is definitely geared towards JavaScript developers who have some basic understanding of and experience with ExtJS 3.0. If you're brand-new to ExtJS, you may want to wait a few weeks until you've spent some time playing with the various components and layouts that ExtJS offers.As an experienced ExtJS developer, I can say with absolute certainty that I learned some new tricks while reading this book. I wrote a full review on my blog ([...]) but here's the short version.:Ramon's approach to explaining the examples is virtually flawless, and the box-style headers make it easy to follow. I haven't seen too many coding books use this technique, so kudos to whoever thought of it!If I had to pick a single reason to buy ExtJS 3.0 Cookbook, it would definitely be Chapter 9 (Well-Charted Territory).Why?For starters, the ExtJS website samples don't do a great job explaining how to use many of the available charts. The online documentation also lacks direction. Jorge is the first person I've seen who thoroughly explains how to use each type of chart, and his examples are both unique and helpful. Kudos!I've read a lot of programming textbooks, and none are nearly as helpful or interesting as ExtJS 3.0 Cookbook. It is a quick read for containing 356 pages, and Jorge Ramon does a fantastic job offering tips and tricks for ExtJS developers.Regardless of your experience level, the ExtJS 3.0 Cookbook will absolutely teach you something new!
Amazon Verified review Amazon
Adam Rackis Jan 30, 2010
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Clear, concise, practical. This book is loaded with useful recipes, which are well explained and easily modified to suit your own project. Honestly one of the best tech books I've bought in a long time.
Amazon Verified review Amazon
S. Chen Mar 06, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
It helped me to understand Ext better. I wished it would have focused on using ext. with MVC though, but it did not.
Amazon Verified review Amazon
Josh Holmes Nov 20, 2009
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
For full disclosure, Packt Publishing sent me a review copy of this book. They did not ask for a positive review, just a review.This is the first book by Jorge Ramon that I've read. This book is exactly what the title says that it is, a Cookbook. It's got 109 solutions to problems solved by Ext JS 3.0. I was expecting, like a lot of other books to get a fill of all of the philosophy behind what they are trying to promote but that wasn't the case. This book just in with no nonsense and gets right to the code.Every chapter is laid out exactly the same. It starts off with a list of problems solved in this chapter and a very short paragraph that gives an explanation to why these are related problems. The rest of the chapter is broken in to "recipes" all of which are laid out exactly the same as each other as well with sections "Introduction", "How to do it", "How it works", an optional "There's more" and a "See also" section. The intro is typically a short paragraph that describes when this recipe is going to be useful and optionally contains a screenshot or two of the solution. The How to do it section is almost all code with just enough text to explain where to put the code that you are looking at. The How it works section explains a little more about the events and the libraries that are at play and how they effect the code snippets that you just wrote. The There's more section points out potential pitfalls or other benefits that this recipe brings to the table. The See also section points out related recipes that you should look at in addition to the recipe that you're looking at.So what's my opinion on the book?if you are trying to understand JavaScript and/or Ext JS 3.0, this book is not the book for you. There are plenty of other books out there that will step you in at a little more manageable pace.However, if you are somewhat familiar with JavaScript and Ext JS 3.0, this is a great recipe book. The code is clean and readable. The problems are problems that I see on a semi-regular basis. I like it for what it is. It's a handy reference and a set of problem/answers that solve discrete problems. It's a good formula and I'm probably going to write a few blog posts in that format to feel it out.The price, $49.00 or 30.99 Pounds is a little steep but if it cuts an hour or two out of your research and development time, it's paid for itself. Also, you can download the code from Packt Publishing in a zip file and copy paste from that so it's definitely going to save you time if you are using Ext JS 3.0. This was something that I missed at first to be honest and only caught when I went back to reread the preface and saw the link to where the source is zipped up.Another interesting note about Packt Publishing is that on their "About Packt Publishing" page in the back of the book, they mention that when they publish a book based on an open source project that they pay royalties back to that project. I don't know how much they pay in royalties to the project but that's a really class thing to do. If one is making money on an open source project, they should contribute to it somehow either through code or financially or both.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela