<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Saki's Blog &#187; extjs</title>
	<atom:link href="http://blog.extjs.eu/tag/extjs/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.extjs.eu</link>
	<description>For good of all productive developers</description>
	<lastBuildDate>Sun, 21 Nov 2010 01:36:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Keeping modified records of EditorGridPanel while paging</title>
		<link>http://blog.extjs.eu/patterns/code-patterns/keeping-modified-records-of-editorgridpanel-while-paging/</link>
		<comments>http://blog.extjs.eu/patterns/code-patterns/keeping-modified-records-of-editorgridpanel-while-paging/#comments</comments>
		<pubDate>Mon, 28 Sep 2009 08:59:44 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Code Patterns]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[Know-how]]></category>
		<category><![CDATA[pattern]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=498</guid>
		<description><![CDATA[<br/>If you modify records of an editable grid with paging and if you then page-out, your changes are lost. Well, they are not lost in fact unless you have set pruneModifiedRecords:true on the strore. The modifications are still available so we just need to apply them. Here is the code fragment that does it:

var grid [...]]]></description>
			<content:encoded><![CDATA[<br/><p>If you modify records of an editable grid with paging and if you then page-out, your changes are lost. Well, they are not lost in fact unless you have set <code><a target="_blank" href="http://www.extjs.com/deploy/dev/docs/?class=Ext.data.Store&#038;member=pruneModifiedRecords">pruneModifiedRecords:true</a></code> on the strore. The modifications are still available so we just need to apply them. Here is the code fragment that does it:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> grid <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">EditorGridPanel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    store<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">Store</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
         listeners<span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>
            load<span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>scope<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> fn<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>store<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
                <span style="color: #006600; font-style: italic;">// loop through modified records</span>
                <span style="color: #003366; font-weight: bold;">var</span> modified <span style="color: #339933;">=</span> store.<span style="color: #660066;">getModifiedRecords</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> modified.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
                    <span style="color: #006600; font-style: italic;">// see if we have a record with same id </span>
                    <span style="color: #006600; font-style: italic;">// and apply changes if yes</span>
                    <span style="color: #003366; font-weight: bold;">var</span> r <span style="color: #339933;">=</span> store.<span style="color: #660066;">getById</span><span style="color: #009900;">&#40;</span>modified<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>r<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #003366; font-weight: bold;">var</span> changes <span style="color: #339933;">=</span> modified<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">getChanges</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>p <span style="color: #000066; font-weight: bold;">in</span> changes<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                            <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>changes.<span style="color: #660066;">hasOwnProperty</span><span style="color: #009900;">&#40;</span>p<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                                r.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span>p<span style="color: #339933;">,</span> changes<span style="color: #009900;">&#91;</span>p<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                            <span style="color: #009900;">&#125;</span>
                        <span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">// eo changes loop</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">// eo modified loop</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">// eo load listener</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">// eo listeners</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// rest of store configuration</span>
&nbsp;
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// rest of grid configuration</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">// eo grid</span></pre></div></div>

<p><b>pruneModifiedRecords must be false (the default) for this to work.</b></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.extjs.eu/patterns/code-patterns/keeping-modified-records-of-editorgridpanel-while-paging/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>New Example &#8211; Ext.ux.MsgBus Demo</title>
		<link>http://blog.extjs.eu/examples/new-example-ext-ux-msgbus-demo/</link>
		<comments>http://blog.extjs.eu/examples/new-example-ext-ux-msgbus-demo/#comments</comments>
		<pubDate>Sun, 20 Sep 2009 21:48:38 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=490</guid>
		<description><![CDATA[<br/>Hi there,
I&#8217;ve just uploaded demo of Ext.ux.MsgBus Plugin at http://examples.extjs.eu/?ex=msgbus.
Enjoy!
]]></description>
			<content:encoded><![CDATA[<br/><p>Hi there,</p>
<p>I&#8217;ve just uploaded demo of <a href="http://blog.extjs.eu/plugins/ext-ux-msgbus-plugin/">Ext.ux.MsgBus Plugin</a> at <a href="http://examples.extjs.eu/?ex=msgbus">http://examples.extjs.eu/?ex=msgbus</a>.</p>
<p>Enjoy!</p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post"><div class="paypal-donations"><input type="hidden" name="cmd" value="_donations" /><input type="hidden" name="business" value="js02@aariadne.com" /><input type="hidden" name="item_number" value="Blog Donation" /><input type="hidden" name="currency_code" value="EUR" /><input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-butcc-donate.gif" name="submit" alt="PayPal - The safer, easier way to pay online." /><img alt="" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" /></div></form>
]]></content:encoded>
			<wfw:commentRss>http://blog.extjs.eu/examples/new-example-ext-ux-msgbus-demo/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>New example &#8211; Drag from Grid to Tree</title>
		<link>http://blog.extjs.eu/examples/new-example-drag-from-grid-to-tree/</link>
		<comments>http://blog.extjs.eu/examples/new-example-drag-from-grid-to-tree/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 20:26:07 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=303</guid>
		<description><![CDATA[<br/>Hi all,
I&#8217;ve just posted new example on how to drag rows from grid to tree.
Enjoy!
http://examples.extjs.eu/?ex=grid2treedrag
]]></description>
			<content:encoded><![CDATA[<br/><p>Hi all,</p>
<p>I&#8217;ve just posted new example on how to drag rows from grid to tree.</p>
<p>Enjoy!</p>
<p><a href="http://examples.extjs.eu/?ex=grid2treedrag" target="_blank">http://examples.extjs.eu/?ex=grid2treedrag</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.extjs.eu/examples/new-example-drag-from-grid-to-tree/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>New Example &#8211; Downloading File</title>
		<link>http://blog.extjs.eu/examples/new-example-downloading-file/</link>
		<comments>http://blog.extjs.eu/examples/new-example-downloading-file/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 08:19:43 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[extjs]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=301</guid>
		<description><![CDATA[<br/>Hi all,
I&#8217;ve just uploaded new example of how to invoke &#8220;Save As..&#8221; dialog when downloading files from the server.
http://examples.extjs.eu
Enjoy!
]]></description>
			<content:encoded><![CDATA[<br/><p>Hi all,</p>
<p>I&#8217;ve just uploaded new example of how to invoke &#8220;Save As..&#8221; dialog when downloading files from the server.</p>
<p><a href="http://examples.extjs.eu/?ex=download" target="_blank">http://examples.extjs.eu</a></p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.extjs.eu/examples/new-example-downloading-file/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>New Example &#8211; Asynchronous Tree State</title>
		<link>http://blog.extjs.eu/examples/new-example-asynchronous-tree-state/</link>
		<comments>http://blog.extjs.eu/examples/new-example-asynchronous-tree-state/#comments</comments>
		<pubDate>Sun, 05 Apr 2009 08:59:13 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=298</guid>
		<description><![CDATA[<br/>Hi, 

I&#8217;ve uploaded example of keeping state of asynchronously loaded tree at http://examples.extjs.eu.


The core state-keeping code is written in the form of plugin so it can be sticked in any existing tree.

Enjoy!
]]></description>
			<content:encoded><![CDATA[<br/><p>Hi, </p>
<p>
I&#8217;ve uploaded example of keeping state of asynchronously loaded tree at <a href="http://examples.extjs.eu/?ex=treestate" target="_blank">http://examples.extjs.eu</a>.
</p>
<p>
The core state-keeping code is written in the form of plugin so it can be sticked in any existing tree.
</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.extjs.eu/examples/new-example-asynchronous-tree-state/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>New Example &#8211; Combo with Remote Store</title>
		<link>http://blog.extjs.eu/examples/new-example-combo-with-remote-store/</link>
		<comments>http://blog.extjs.eu/examples/new-example-combo-with-remote-store/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 11:58:36 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Know-how]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=295</guid>
		<description><![CDATA[<br/>Hi, 
I&#8217;ve just uploaded a full-fledged example of combo with remote store at http://examples.extjs.eu.
Enjoy!
]]></description>
			<content:encoded><![CDATA[<br/><p>Hi, </p>
<p>I&#8217;ve just uploaded a full-fledged example of combo with remote store at <a href="http://examples.extjs.eu/?ex=combo" target="_blank">http://examples.extjs.eu</a>.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.extjs.eu/examples/new-example-combo-with-remote-store/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Factory Function File Pattern</title>
		<link>http://blog.extjs.eu/know-how/factory-function-file-pattern/</link>
		<comments>http://blog.extjs.eu/know-how/factory-function-file-pattern/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 13:50:04 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[File Patters]]></category>
		<category><![CDATA[Know-how]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=266</guid>
		<description><![CDATA[<br/>You know, I&#8217;m not very big fan of factory functions, nevertheless, I&#8217;m aware of the fact that they may be necessary in some situations. Here is the file pattern that works (briefly tested).
Keep each factory function in a separate file name of which should be Namespace.Factory.functionName.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// vim: ts=4:sw=4:nu:fdc=4:nospell
/*global Ext, MyNamespace */
/**
 * @class MyNamespace.Factory
 *
 [...]]]></description>
			<content:encoded><![CDATA[<br/><p>You know, I&#8217;m not very big fan of factory functions, nevertheless, I&#8217;m aware of the fact that they may be necessary in some situations. Here is the file pattern that works (briefly tested).</p>
<p><b>Keep each factory function in a separate file name of which should be <code>Namespace.Factory.functionName.js</code></b></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// vim: ts=4:sw=4:nu:fdc=4:nospell</span>
<span style="color: #009966; font-style: italic;">/*global Ext, MyNamespace */</span>
<span style="color: #006600; font-style: italic;">/**
 * @class MyNamespace.Factory
 *
 * A Factory function pattern
 *
 * @author    Ing. Jozef Sakáloš
 * @copyright (c) 2009, by Ing. Jozef Sakáloš
 * @date      17. March 2009
 * @version   0.1
 * @revision  $Id$
 *
 * @license MyNamespace.Factory.myPanel.js is licensed under the terms of
 * the Open Source LGPL 3.0 license. Commercial use is permitted to the extent
 * that the code/component(s) do NOT become part of another Open Source or 
 * Commercially licensed development library or toolkit 
 * without explicit permission.
 * 
 * &lt;p&gt;License details: &lt;a href=&quot;http://www.gnu.org/licenses/lgpl.html&quot;
 * target=&quot;_blank&quot;&gt;http://www.gnu.org/licenses/lgpl.html&lt;/a&gt;&lt;/p&gt;
 */</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// create namespace</span>
Ext.<span style="color: #660066;">ns</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'MyNamespace.Factory'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">/**
 * @method myPanel
 * @param {Object} config
 * A config object
 * @return {Ext.Panel}
 */</span>
MyNamespace.<span style="color: #660066;">Factory</span>.<span style="color: #660066;">myPanel</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>config<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// pre-instantiation code</span>
	<span style="color: #003366; font-weight: bold;">var</span> defaults <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// put your defaults here</span>
		<span style="color: #006600; font-style: italic;">// but avoid id, el, contentEl, renderTo, applyTo, or similar</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// eo defaults object</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// create config object</span>
	<span style="color: #003366; font-weight: bold;">var</span> cfg <span style="color: #339933;">=</span> Ext.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> config<span style="color: #339933;">,</span> defaults<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// instantiate</span>
	<span style="color: #003366; font-weight: bold;">var</span> cmp <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">Panel</span><span style="color: #009900;">&#40;</span>cfg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// post-instantiation code</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// return the created component</span>
	<span style="color: #000066; font-weight: bold;">return</span> cmp<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">// eo function MyNamespace.Factory.myPanel</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// eof</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.extjs.eu/know-how/factory-function-file-pattern/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Writing a Big Application in Ext (Part 3)</title>
		<link>http://blog.extjs.eu/know-how/writing-a-big-application-in-ext-part-3/</link>
		<comments>http://blog.extjs.eu/know-how/writing-a-big-application-in-ext-part-3/#comments</comments>
		<pubDate>Sat, 14 Mar 2009 12:53:34 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Know-how]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[extjs]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=234</guid>
		<description><![CDATA[<br/>Important
If you have not already done so, study Writing a Big Application in Ext (Part 1) and Writing a Big Application in Ext (Part 2)before you read this article. It would be very hard, if not impossible, to understand concepts explained here before you fully understand the first and second part.
Introduction
Helping on the forum and [...]]]></description>
			<content:encoded><![CDATA[<br/><h2 style="margin-top:30px"><em>Important</em></h2>
<p>If you have not already done so, study <a href="http://blog.extjs.eu/know-how/writing-a-big-application-in-ext/" style="font-size:125%;">Writing a Big Application in Ext (Part 1)</a> and <a href="http://blog.extjs.eu/know-how/writing-a-big-application-in-ext-part-2/" style="font-size:125%;">Writing a Big Application in Ext (Part 2)</a>before you read this article. It would be very hard, if not impossible, to understand concepts explained here before you fully understand the first and second part.</p>
<h1>Introduction</h1>
<p>Helping on the <a href="http://extjs.com/forum" target="_blank">forum</a> and reading code of others that failed to extend Ext classes, revealed more errors that users, especially beginners, commonly make. Therefore, I&#8217;ve decided to start this article that will collect these errors and will explain why the errors <i>are</i> errors. I mean it as loosely ended as I may discover more errors and ways of avoiding them so I plan just to add them to <i>this</i> article, not endlessly create parts 4, 5, etc&#8230;</p>
<h1><span style="font-size:12px">&#8230; continued:</span> Most Common Sources of Troubles</h1>
<p>Here we go:</p>
<ol>
<li><a href="#unnecessary-extending">Unnecessary Extending</a></li>
<li><a href="#adding-objects-to-prototype">Adding Objects to Prototype</a></li>
<li><a href="#hard-coding-ids">Hard Coding ids</a></li>
</ol>
<p>&nbsp;</p>
<h2 id="unnecessary-extending">Unnecessary Extending</h2>
<p>The main reasons for extending are:</p>
<ul>
<li>re-usability</li>
<li>adding functionality</li>
<li>combination of them</li>
</ul>
<p>so we extend if we need a re-usable component <b>or</b> we need to add a functionality (new methods) or both. If we are after <b>re-usability</b> the extension can be as simple as:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">MyPortlet <span style="color: #339933;">=</span> Ext.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>Ext.<span style="color: #660066;">Panel</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
     anchor<span style="color: #339933;">:</span><span style="color: #3366CC;">'100%'</span>
    <span style="color: #339933;">,</span>draggable<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span>
    <span style="color: #339933;">,</span>defaultType<span style="color: #339933;">:</span><span style="color: #3366CC;">'mygraph'</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>You see what happens? We are going to use MyPortlet many times so instead of scatter the above configuration in 10,000 lines application code 100 times, we create this simple extension and we save 297 lines of code. </p>
<p>The other aspect is that if we upgrade our &#8216;mygraph&#8217; to &#8216;mygraph_new&#8217; the only place where to change it is our extension saving us searching out code for all occurrences of &#8216;mygraph&#8217; (100 times) and replacing it with &#8216;mygraph_new&#8217; 100 times.</p>
<p>(Well, 100 is exaggerated, but you get the point, right?)</p>
<p>If we are after <b>adding functionality</b>, which can be also simple, we add some &#8220;logic&#8221;:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">MyPanel <span style="color: #339933;">=</span> Ext.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>Ext.<span style="color: #660066;">Panel</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
    onRender<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        MyPanel.<span style="color: #660066;">superclass</span>.<span style="color: #660066;">onRender</span>.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Rendered'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Here we add some logic to Panel, it <b>does more</b> that it did before. </p>
<p><b>There is no need to extend in all other cases.</b></p>
<p>&nbsp;</p>
<h2 id="adding-objects-to-prototype">Adding Objects to Prototype</h2>
<p>Run this code first:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">http-equiv</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/html; charset=utf-8&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;ext/resources/css/ext-all.css&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;ext/adapter/ext/ext-base.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;ext/ext-all-debug.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;page-title&quot;</span>&gt;</span>Extending Error: Object in prototype<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
  Ext.BLANK_IMAGE_URL = 'ext/resources/images/default/s.gif';
  Ext.onReady(function() {
    MyPanel = Ext.extend(Ext.Panel, {
         layout:'fit'
        ,panelConfig: {
            bodyBg:'red'
        }
&nbsp;
        ,initComponent:function() {
            var config = {
                bodyStyle:'background-color:' + this.panelConfig.bodyBg
            }; // eo config object
&nbsp;
            // apply config
            Ext.apply(this, Ext.apply(this.initialConfig, config));
&nbsp;
            MyPanel.superclass.initComponent.apply(this, arguments);
        } // eo function initComponent
&nbsp;
        ,applyBackground:function(color) {
            this.panelConfig.bodyBg = color;
            this.body.applyStyles({'background-color':color});
        } // eo function applyBackground
&nbsp;
    }); // eo extend
&nbsp;
    var p1 = new MyPanel({
         title:'Panel with Blue Background'
        ,renderTo:Ext.getBody()
        ,width:240
        ,height:160
    });
&nbsp;
    p1.applyBackground('blue');
&nbsp;
    var p2 = new MyPanel({
         title:'Panel with Red Background'
        ,renderTo:Ext.getBody()
        ,width:240
        ,height:160
    });
&nbsp;
  });
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<p>What do we expect? It is written in titles of panels: Top panel (p1) should have <b>blue</b> body background because we set it to it after it is created. And bottom panel (p2) should have <b>red</b> because we just create default <code>MyPanel</code>.</p>
<p><b>But it is blue too!!! Why?</b> The reason is simple: <code>panelConfig</code> is object that is created during <i>class definition</i> and it is added to MyPanel prototype. Objects (arrays too) are accessed by reference so p1 and p2 <b>share the same instance of <code>panelConfig</code></b>. Setting <code>bodyBg</code> property in <code>applyBackground</code> method changes this single instance of <code>panelConfig</code> object. So we create p2 with blue background too.</p>
<p>You see, here it is clearly and immediately visible that something went wrong but making this error can lead to weeks of wasted debugging time in real applications. Imagine you have a store in prototype&#8230;</p>
<p>&nbsp;</p>
<h2 id="hard-coding-ids">Hard Coding ids</h2>
<p>Very simple, but deadly mistake is to set ids in the extension either to the main extension object or on its items, toolbars, buttons, etc. If a hard coded ids are set we cannot create two or more instances of our extension, can we?</p>
<h1>Loose End</h1>
<p>That&#8217;s all for now but if I discover more errors I will add them above. </p>
<p>Stay tuned!</p>
<p><strong><em>Do not forget to read <a href="http://blog.extjs.eu/know-how/writing-a-big-application-in-ext/">Part 1</a> and <a href="http://blog.extjs.eu/know-how/writing-a-big-application-in-ext-part-2/">Part 2</a> of this article. </em></strong></p>
<p>Follow up: <strong><a href="http://blog.extjs.eu/know-how/factory-functions-in-ext-extensions/">Factory Functions in Ext Extensions (Abstract Classes)</a></strong></p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post"><div class="paypal-donations"><input type="hidden" name="cmd" value="_donations" /><input type="hidden" name="business" value="js02@aariadne.com" /><input type="hidden" name="item_number" value="Blog Donation" /><input type="hidden" name="currency_code" value="EUR" /><input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-butcc-donate.gif" name="submit" alt="PayPal - The safer, easier way to pay online." /><img alt="" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" /></div></form>
]]></content:encoded>
			<wfw:commentRss>http://blog.extjs.eu/know-how/writing-a-big-application-in-ext-part-3/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>How to remove all children of a tree node</title>
		<link>http://blog.extjs.eu/know-how/how-to-remove-all-children-of-a-tree-node/</link>
		<comments>http://blog.extjs.eu/know-how/how-to-remove-all-children-of-a-tree-node/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 21:34:29 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Know-how]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=221</guid>
		<description><![CDATA[<br/>Suppose we want to remove all children of the node node:

while&#40;node.firstChild&#41; &#123;
    node.removeChild&#40;node.firstChild&#41;;
&#125;

That&#8217;s all there is to it
]]></description>
			<content:encoded><![CDATA[<br/><p>Suppose we want to remove all children of the node <code><b>node</b></code>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>node.<span style="color: #660066;">firstChild</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    node.<span style="color: #660066;">removeChild</span><span style="color: #009900;">&#40;</span>node.<span style="color: #660066;">firstChild</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>That&#8217;s all there is to it</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.extjs.eu/know-how/how-to-remove-all-children-of-a-tree-node/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>New Example</title>
		<link>http://blog.extjs.eu/examples/new-example-8/</link>
		<comments>http://blog.extjs.eu/examples/new-example-8/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 21:49:18 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[news]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=208</guid>
		<description><![CDATA[<br/>Hi,
I&#8217;ve just uploaded the complex example of data binding of grid record to another two components.
http://examples.extjs.eu
Enjoy!
]]></description>
			<content:encoded><![CDATA[<br/><p>Hi,</p>
<p>I&#8217;ve just uploaded the complex example of data binding of grid record to another two components.</p>
<p><a target="_blank" href="http://examples.extjs.eu?ex=databind">http://examples.extjs.eu</a></p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.extjs.eu/examples/new-example-8/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

