<?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>VinylFox &#187; ExtJS Tutorials</title>
	<atom:link href="http://www.vinylfox.com/category/extjs/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vinylfox.com</link>
	<description>The Playground of VinylFox (Shea Frederick)</description>
	<lastBuildDate>Tue, 24 Jan 2012 14:26:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Each Second Counts, or Not</title>
		<link>http://www.vinylfox.com/each-second-counts-or-not/</link>
		<comments>http://www.vinylfox.com/each-second-counts-or-not/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 16:37:06 +0000</pubDate>
		<dc:creator>Shea Frederick</dc:creator>
				<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[ExtJS Tutorials]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.vinylfox.com/?p=741</guid>
		<description><![CDATA[Every once and a while I glance upon a chunk of code that just screams at me to be optimized. From that point on, all I can do is think about how much faster it would be if I just did this or that. Today I had one of those moments when looking at a [...]]]></description>
			<content:encoded><![CDATA[<p>Every once and a while I glance upon a chunk of code that just screams at me to be optimized. From that point on, all I can do is think about how much faster it would be if I just did this or that. Today I had one of those moments when looking at a co-workers code &#8211; I noticed that they had scoped an <em>each</em> loop that did not use scope (context). This got me wondering if there were any optimizations within the each loop that made it run faster without scope, so I took a look.</p>
<h2>Call &#038; Scope</h2>
<p>So as it turns out, the simple answer is no. The <em>each</em> method uses the <em>call</em> method of the <em>Function</em> constructor to apply scope to the function executed on each pass of the loop. When no scope is provided to the each method, it uses the current item as the scope &#8211; which is kinda strange, but whatever.</p>
<h2>No Scope</h2>
<p>Here is my smart idea &#8211; don&#8217;t use the <em>call</em> method if there is no scope provided. Simple, and it seems like it would help speed things up, so let&#8217;s give it a shot.</p>
<p><textarea class="js" cols="100" name="code">Ext.each = function(array, fn, scope){<br />
    if(Ext.isEmpty(array, true)){<br />
        return;<br />
    }<br />
    if(!Ext.isIterable(array) || Ext.isPrimitive(array)){<br />
        array = [array];<br />
    }<br />
    for(var i = 0, len = array.length; i < len; i++){<br />
        if((scope) ? fn.call(scope, array[i], i, array) : fn(array[i], i, array) === false){<br />
            return i;<br />
        }<br />
    }<br />
};</textarea></p>
<p>The basic change here is on line 9 where I check to see if scope was passed in, and decide to either <em>call </em>the function to apply scope or just execute it directly.</p>
<p><textarea class="js" cols="100" name="code">// original<br />
fn.call(scope || array[i], array[i], i, array)<br />
// my version<br />
(scope) ? fn.call(scope, array[i], i, array) : fn(array[i], i, array)</textarea></p>
<p>Using my current web app as the guinea pig, this version ran between <strong>5-18% faster</strong> in Firefox than it&#8217;s non scope checking predecessor. Internet Explorer&#8217;s results were so far scattered across the board that I could not draw a conclusion &#8211; in some tests 50% faster, in others 350% slower. As usual, IE left me confused, so im just going to ignore that for now.</p>
<h2>Can We Do Better?</h2>
<p>The next thing that caught my eye was the fact that when a single item is passed into the <em>each </em>method, it is shoved into an array and sent through the <em>for </em>loop &#8211; this seemed like a place for improvement.</p>
<p><textarea class="js" cols="100" name="code">Ext.each = function(array, fn, scope){<br />
    if(Ext.isEmpty(array, true)){<br />
        return;<br />
    }<br />
    if (!Ext.isIterable(array) || Ext.isPrimitive(array)) {<br />
	if ((scope) ? fn.call(scope, array, 0, array) : fn(array, 0, array) === false) {<br />
		return 0;<br />
	}<br />
    } else {<br />
	for (var i = 0, len = array.length; i < len; i++) {<br />
		if ((scope) ? fn.call(scope, array[i], i, array) : fn(array[i], i, array) === false) {<br />
			return i;<br />
		}<br />
	}<br />
    }<br />
};</textarea></p>
<p>In this case I have simply taken any single non array item that is passed in and executed the function immediately, bypassing the <em>for </em>loop. Results of this change were not noticeable, and matched almost identically with my previous version. Upon closer inspection, it turns out that this case is never reached, in other words, there is always an array passed in. Go figure.</p>
<h2>Summary</h2>
<p>The moral of the story here is to think simple when trying to optimize code, otherwise we end up going to far into optimizing and actually make the code more complex and likely slower, but this does not mean that the code with the fewest characters or lines will be the quickest. Experimenting is fun, so I would encourage everyone to try things like this just to see how they work and in turn gain a better understanding of how the methods you use every day actually work. Priceless.</p>
<p>Code for these tests can be downloaded from my <a href="http://github.com/VinylFox/ExtJS.ux.Misc">Ext.ux.Misc</a> Git repo on Github.</p>
<p>My next step is to test each loop &#8220;unrolling&#8221; to see what the effect is&#8230;let me know what you have tried on your own, and how it has worked out for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinylfox.com/each-second-counts-or-not/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Patterns &#8211; Using Ext JS Override</title>
		<link>http://www.vinylfox.com/patterns-using-ext-js-override/</link>
		<comments>http://www.vinylfox.com/patterns-using-ext-js-override/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 11:59:29 +0000</pubDate>
		<dc:creator>Shea Frederick</dc:creator>
				<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[ExtJS Tutorials]]></category>

		<guid isPermaLink="false">http://www.vinylfox.com/?p=732</guid>
		<description><![CDATA[If you have ever posted a bug report about an Ext JS component then you have likely heard about Override&#8216;s. These Overrides are a way for us to change the way the base library works, usually because of a defect, but sometimes just because we don&#8217;t like or agree with the way something works. Here [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.vinylfox.com/wp-content/uploads/2010/06/cubicle.jpg" class="lightbox"><img src="http://www.vinylfox.com/wp-content/uploads/2010/06/cubicle-150x150.jpg" alt="" style="border: 1px solid rgb(0, 0, 0); margin: 0pt 10px 10px 0pt;" title="Cubicle" width="150" height="150" class="alignleft size-thumbnail wp-image-760" /></a>If you have ever posted a bug report about an Ext JS component then you have likely heard about <em>Override</em>&#8216;s.</p>
<p>These <em>Overrides</em> are a way for us to change the way the base library works, usually because of a defect, but sometimes just because we don&#8217;t like or agree with the way something works. Here we are going to cover how to write a basic <em>Override </em>that &#8216;fixes&#8217; or adds a feature to something in the library.</p>
<h2>Why?</h2>
<p>The last thing we want to do is edit any of the Ext JS distribution files, such as ext-all.js or ext-core.js, we want to instead apply our changes into the library without touching the library files directly, using the library itself to overwrite specific functions where needed. Editing the library files directly would make upgrading nearly impossible. This is where the <em>Override </em>method comes in to help.</p>
<h2>Downfall</h2>
<p>Overriding a base function causes an extra maintenance responsibility &#8211; a shift of responsibility &#8211; simple as that. Though less of a problem than say, editing the ext-all.js file. Every upgrade of the base library (Ext JS) we make requires that we re-examine all of our <em>Overrides </em>to make sure they still sync up with code from the base library, and that the problem were overriding has not been fixed by the Ext JS development team.</p>
<h2>Override</h2>
<p><img width="303" height="170" style="border: 1px solid rgb(0, 0, 0); margin: 0px 0px 10px 10px;" class="alignright wp-image-752" title="Cascade Windows" src="http://www.vinylfox.com/wp-content/uploads/2010/06/cascade.png" alt="Cascade Windows">Were going to start with an <em>override </em>that adds a feature to the library that we desperately need! Or at least that&#8217;s what our boss tells us.</p>
<p>We are adding an option to cascade the placement of new windows based on the position of the previous window. The reason I am adding this as an Override instead of a Plugin or Extension is because im lobbying to get it added as a feature to the library (not really) and when it gets added to the library and I upgrade, I will be able to simply remove my override and continue with life.</p>
<p>The goal is to end up with an no Overrides in your application, by reporting bugs and enhancements to the Ext JS team, and following through so they get fixed in the library.</p>
<p>The Override method of the Ext JS library will take the function(s) we pass to it and overwrite functions of the same name within the component specified. The previously defined function that were replacing are completely removed, and the new ones put in their place.</p>
<p>Two arguments are accepted for the <em>Override </em>method, the first is the <strong>class</strong> that we are overriding, and the second is an <strong>object with the methods</strong> we are overriding.</p>
<p><textarea name="code" cols="100" class="js" style="display: none;">Ext.override(/*CLASS*/, /*METHODS OBJECT*/{<br />
    /*METHOD NAME*/:function(){<br />
        /*DO IT!*/<br />
    },<br />
    /*ANOTHER METHOD NAME*/:function(){<br />
        /*DO IT MORE!*/<br />
    }<br />
});</textarea></p>
<h2>The Code</h2>
<p>We start by copying the source of the original method from the Ext JS source files that come with the SDK download (located in the src folder), in this case it&#8217;s the beforeShow method of Ext.Window (in Window.js). Using the source as a starting point, we can modify the function to do what we need.</p>
<p><textarea name="code" cols="100" class="js" style="display: none;">Ext.override(Ext.Window, {<br />
    beforeShow : function(){<br />
	    delete this.el.lastXY;<br />
	    delete this.el.lastLT;<br />
	    if(this.x === undefined || this.y === undefined){<br />
    		var xy = this.el.getAlignToXY(this.container, &#8216;c-c&#8217;),<br />
    		    pos = this.el.translatePoints(xy[0], xy[1]);<br />
	    	if(this.position === &#8216;cascade&#8217;){<br />
	    		this.x = Ext.winPosx = (Ext.winPosx)? Ext.winPosx+20 : pos.left;<br />
	    		this.y = Ext.winPosy = (Ext.winPosy)? Ext.winPosy+20 : pos.top;<br />
	    	}else{<br />
	    		this.x = this.x === undefined? pos.left : this.x;<br />
	    		this.y = this.y === undefined? pos.top : this.y;<br />
	    	}<br />
	    }<br />
	    this.el.setLeftTop(this.x, this.y);<br />
	    if(this.expandOnShow){<br />
	        this.expand(false);<br />
	    }<br />
	    if(this.modal){<br />
	        Ext.getBody().addClass(&#8216;x-body-masked&#8217;);<br />
	        this.mask.setSize(Ext.lib.Dom.getViewWidth(true), Ext.lib.Dom.getViewHeight(true));<br />
	        this.mask.show();<br />
	    }<br />
	}<br />
});</textarea></p>
<p>NOTE: Find the <a href="http://github.com/VinylFox/ExtJS.Patterns/blob/master/Ext.override.js" target="_blank">source</a> on my Github <a href="http://github.com/VinylFox/ExtJS.Patterns" target="_blank">ExtJS.Patterns</a> repo.</p>
<p>Here it has been modified to add an if statement that looks at our new <em>position </em>config to see if its been set to &#8216;cascade&#8217;. From there we can add 20 pixels to both the x and y axis of the previous window position to place it cascaded. The previous window position has been stored in the winPosx/y properties of the Ext object. The else simply runs the original window position code.</p>
<p>This is all overwriting the original <em>beforeShow </em>method of the <em>Window</em>, which simply placed the window in the center of it&#8217;s container. This change applies to every single window that is created, even windows that might be extended from the base window class, it&#8217;s essentially changing the source code of the Ext JS library, without touching the source files.</p>
<h2>How About Fixes</h2>
<p>Fixes are really the same thing, if were adding new features or fixing problems it&#8217;s all the same as far as Overrides are concerned, though most of the time an Override would be used to fix a bug. Need I say more?</p>
<h2>Summary</h2>
<p>Overrides are great for adding features or fixes to the library code without disturbing the source files. Keep this in mind when you run into a bug in the library and need to &#8216;patch&#8217; it to get things working, or have required features that should be part of the base library. The goal should be having <strong>NO </strong>overrides at all, which can be achieved by reporting bugs and posting feature requests. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinylfox.com/patterns-using-ext-js-override/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Patterns &#8211; Using Ext JS Sequence and Intercept</title>
		<link>http://www.vinylfox.com/patterns-using-ext-js-sequence-and-intercept/</link>
		<comments>http://www.vinylfox.com/patterns-using-ext-js-sequence-and-intercept/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 11:53:01 +0000</pubDate>
		<dc:creator>Shea Frederick</dc:creator>
				<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[ExtJS Tutorials]]></category>
		<category><![CDATA[Patterns]]></category>

		<guid isPermaLink="false">http://www.vinylfox.com/?p=577</guid>
		<description><![CDATA[I&#8217;m going to run through the usage of a little unknown feature of Ext JS called Sequence and Intercept. These are a pair of related methods built into Ext JS that we can use to add functionality or add fixes to the library without having to override or create a new component. Why is this [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m going to run through the usage of a little unknown feature of Ext JS called <a href="http://www.extjs.com/deploy/dev/docs/?class=Function&#038;member=createSequence">Sequence</a> and <a href="http://www.extjs.com/deploy/dev/docs/?class=Function&#038;member=createInterceptor">Intercept</a>. These are a pair of related methods built into Ext JS that we can use to add functionality or add fixes to the library without having to override or create a new component. Why is this important? We will take a look at our options to get an idea of the restrictions imposed by each of them, but first I want to frame this all with a scenario.</p>
<h2>Scenario (our use case)</h2>
<p><a href="http://www.vinylfox.com/wp-content/uploads/2009/11/required.gif" class="lightbox"><img src="http://www.vinylfox.com/wp-content/uploads/2009/11/required-150x150.gif" alt="" title="required" width="150" height="150" class="alignright size-thumbnail wp-image-724" align="right"/></a>Our goal here is to create a &#8216;required&#8217; indicator on all form fields by setting a required flag on the configuration object of each component &#8211; in our case, form fields. The code base (the web app) is already in place, so this is a web application that has been completed and is in use.</p>
<p>We have a few options available to make this happen:</p>
<ul>
<li>Override</li>
<li>Extend</li>
<li>Intercept/Sequence</li>
</ul>
<p>Lets take a look at the benefits and problems imposed by these methods.</p>
<h2>Override</h2>
<p>Of course one way to get what we want is to override a particular method in the component were using. If were lucky, there is a stub function in place that we can use, but more often than not, this is not the case. What were left with is having to copy code from the library source files and modify it to fit our needs &#8211; not the optimal solution. This means that each time the Ext JS codebase is updated, we need to check the changes against our overridden copy. This is a maintenance nightmare, though there are cases where this is the optimal solution.</p>
<h2>Extend (new Component)</h2>
<p>The better of our two options is the Extend method. This way creates a copy of the component that we can modify to fit our needs. Not a bad solution all and all. The two problems here are that any components that inherit from our extended component will not get our new functionality, and we now have a copy of the component with a new name, so each place we use that component needs to use our updated component name, ie: &#8216;mysupertextfield&#8217; instead of &#8216;textfield&#8217;. Again, not a big deal, but if I already have a complete web app, and im adding a bit of functionality to a common component, I don&#8217;t want to have to run a find/replace on the entirety of my code.</p>
<h2>Meet intercept/sequence</h2>
<p>My personal favorite in this situation is to add our functionality either before or after an existing method. The intercept method of Ext JS takes whatever function you provide and executes it right before whatever method in the component you specify. The function we define is also executed in the same scope as the method were intercepting.</p>
<p><textarea class="js" cols="100" name="code">Ext.intercept(Ext.form.Field.prototype, &#8216;initComponent&#8217;, function() {<br />
	var fl = this.fieldLabel, ab = this.allowBlank;<br />
	if (ab === false &#038;&#038; fl) {<br />
		this.fieldLabel = &#8216;<span style="color:red;">*</span> &#8216;+fl;<br />
	} else if (ab === true &#038;&#038; fl) {<br />
		this.fieldLabel = &#8216;&nbsp; &#8216;+fl;<br />
	}<br />
});</textarea></p>
<p>NOTE: Find the <a href="http://github.com/VinylFox/ExtJS.Patterns/blob/master/Ext.intercept.js" target="_blank">source</a> on my Github <a href="http://github.com/VinylFox/ExtJS.Patterns" target="_blank">ExtJS.Patterns</a> repo.</p>
<p>With this override, we can use the existing allowBlank flag to trigger the required indicator</p>
<p><textarea class="js" cols="100" name="code">&#8230;<br />
{<br />
        fieldLabel: &#8216;Last Name&#8217;,<br />
        allowBlank: false,<br />
        name: &#8216;last&#8217;<br />
},{<br />
        fieldLabel: &#8216;Company&#8217;,<br />
        allowBlank: true,<br />
        name: &#8216;company&#8217;<br />
}<br />
&#8230;</textarea></p>
<p>In this case, intercept seems to be the perfect fit, allowing us to add a visual required indicator to each component that is extended from the Field base class. The one downside I see here is that this code is executed every single time a field is created, so be sure to make it lean.</p>
<p>We could also use Sequence to achieve this, which uses the same syntax and concept as Intercept, but executes after the method we define has executed instead of before. The order of execution is like this:</p>
<ul>
<li>Intercept</li>
<li>Method (ie: initComponent)</li>
<li>Sequence</li>
</ul>
<h2>Summary</h2>
<p>I hope this has helped. Over the next few weeks I will be blogging about the many Ext JS patterns available, their pros and cons, and practical usage. Each one will have code paired with it on <a href="http://github.com/VinylFox/ExtJS.Patterns" target="_blank">Github</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinylfox.com/patterns-using-ext-js-sequence-and-intercept/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Some Common ExtJS Error Messages Explained</title>
		<link>http://www.vinylfox.com/some-common-extjs-error-messages-explained/</link>
		<comments>http://www.vinylfox.com/some-common-extjs-error-messages-explained/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 13:05:18 +0000</pubDate>
		<dc:creator>Shea Frederick</dc:creator>
				<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[ExtJS Tutorials]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.vinylfox.com/?p=434</guid>
		<description><![CDATA[Its Monday morning, and it truly feels like it today. My coffee is not even finished yet, and I already found myself making a dumb mistake and spending too much time troubleshooting it, so I thought I would share with you a few common errors that we might run across when writing ExtJS applications. With [...]]]></description>
			<content:encoded><![CDATA[<p>Its Monday morning, and it truly feels like it today. My coffee is not even finished yet, and I already found myself making a dumb mistake and spending too much time troubleshooting it, so I thought I would share with you a few common errors that we might run across when writing ExtJS applications. With any luck, these will stick to the inside of your cranium &#8211; and hopefully mine as well.</p>
<h2>this.config[col] is undefined</h2>
<p>The <i>autoExpandColumn</i> feature of the ColumnModel accepts an &#8216;id&#8217; as the argument, this &#8216;id&#8217; needs to match the &#8216;id&#8217; given to the Column configuration. </p>
<p><textarea class="js" cols="100" name="code">{<br />
	columns: [{<br />
		id: 'not_so_super_column_id',  // column id defined<br />
		header: 'Super Duper',<br />
		dataIndex: 'superduper'<br />
	}],<br />
	&#8230;,<br />
	autoExpandColumn: &#8216;super_duper_column_id&#8217;  // wrong column id used &#8211; fail!<br />
}</textarea></p>
<p>Another thing to keep in mind, is that while it works sometimes, the value for <em>autoExpandColumn </em>should NOT be a column index &#8211; the id of the column should always be used.</p>
<h2>types[config.xtype || defaultType] is not a constructor (b[d.xtype || e] is not a constructor)</h2>
<p>This happens when trying to instantiate (create) a component that does not exist, the most common reason is a typo or spelling error. For instance, using &#8216;gridpanel&#8217; as the xtype instead of &#8216;grid&#8217; &#8211; which is a mistake I make often myself. Sometimes we can forget a level of namespacing, like using <em>Ext.FormPanel</em> instead of the proper <em>Ext.form.FormPanel</em>.</p>
<p><textarea class="js" cols="100" name="code">{<br />
	xtype: &#8216;formpanel&#8217;  // fail<br />
},{<br />
	xtype: &#8216;form&#8217;  // win!<br />
}</textarea></p>
<p>Another one I always run into is typing &#8216;combobox&#8217; instead of the correct &#8216;combo&#8217; for the xtype &#8211; a list of xtypes can be found in the <a href="http://www.extjs.com/deploy/dev/docs/?class=Ext.Component">ExtJS documentation under Ext.Component</a>.</p>
<h2>this.addEvents is not a function</h2>
<p>This is not a <em>new </em>problem (you like that pun?) but unfortunately the error message sends us off in the wrong direction. When this message appears it sounds like its an event related problem, but what it simply means is that we have forgotten to preface a constructor with the &#8216;new&#8217; operator.</p>
<p><textarea class="js" cols="100" name="code">Ext.form.TextField({}); // fail<br />
new Ext.form.TextField({}); // win!</textarea></p>
<h2>el is null</h2>
<p>So with this one, its a little easier to figure out what went wrong just from the error message. In shorthand variable naming, a couple of letters are picked out of a longer word that phonetically make sense, and do not spell something else or sound like other commonly used words. So in this case &#8216;el&#8217; is short for <strong>EL</strong>ement. As the error message says &#8216;el is null&#8217;, which if we translate from geek speak to English it says &#8216;html  element does not exist&#8217;.</p>
<p><textarea class="js" cols="100" name="code"></p>
<div id="sweet_dude"></div>
<p>new Ext.Button({<br />
	text: &#8216;Clicky&#8217;,<br />
	renderTo: &#8216;dude_sweet&#8217; // does not match the id!<br />
});</textarea></p>
<h2>f.convert is not a function</h2>
<p>This one is not so common, but still happens every once and a while. It means that your data reader was trying to read the data you passed to your store with a particular data type that did not exist. Thats allot to take in, so lets take a look at this example.</p>
<p><textarea class="js" cols="100" name="code">var myStore = new Ext.data.ArrayStore({<br />
	fields: [{<br />
		name:'fullname',<br />
		type:'badass'<br />
	}, {<br />
		name:'first',<br />
		type:'string'<br />
	}]<br />
});</textarea></p>
<p>In this example the &#8216;fullname&#8217; column has a datatype of &#8216;badass&#8217;, which does not exist. On the flip side, the datatype for &#8216;first&#8217; of &#8216;string&#8217; does exist.</p>
<h2>Summary</h2>
<p>Now if we can just keep these in our memory, we might be able to have a productive day  -or just drink more coffee and see how that pans out.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinylfox.com/some-common-extjs-error-messages-explained/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Four Tips for Staying on Track With Scope in ExtJS</title>
		<link>http://www.vinylfox.com/four-tips-for-staying-on-track-with-scope-in-extjs/</link>
		<comments>http://www.vinylfox.com/four-tips-for-staying-on-track-with-scope-in-extjs/#comments</comments>
		<pubDate>Tue, 26 May 2009 21:01:57 +0000</pubDate>
		<dc:creator>Shea Frederick</dc:creator>
				<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[ExtJS Tutorials]]></category>
		<category><![CDATA[Scope]]></category>

		<guid isPermaLink="false">http://www.vinylfox.com/?p=262</guid>
		<description><![CDATA[We have all been there, mucking around with code, thinking to ourselves &#8220;why does this component not have an X method?&#8221; or &#8220;where did all my scoped vars run off to?&#8221; spending valuable time debugging your code just to eventually find out that you have gone out of scope and didn&#8217;t know it. The unfortunate [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.vinylfox.com/wp-content/uploads/2009/05/img_0902-1-300x282.jpg" alt="SCOPE DONKEY!" title="SCOPE DONKEY!" width="300" height="282" class="alignleft size-medium wp-image-277"  align="left" style="margin: 10px;" />We have all been there, mucking around with code, thinking to ourselves &#8220;why does this component not have an X method?&#8221; or &#8220;where did all my scoped vars run off to?&#8221; spending valuable time debugging your code just to eventually find out that you have gone out of scope and didn&#8217;t know it. The unfortunate thing is that its so incredibly easy to loose track of your scope, and not often are the results of whats going wrong making it glaringly obvious that your scope has been lost.</p>
<p>A solution that works for me has taken the shape of a sticky note &#8211; I affectionately refer to this as the &#8220;SCOPE DONKEY!&#8221; note. Its my reminder for things to look for when I get that icky feeling that there is a scope related problem. So here is the rundown:</p>
<h2>Each</h2>
<p>Using <i>Ext.each</i> or the <i>each</i> method of an array or store, etc. is the first easy way to loose scope. The following bit of code looses scope, so our <i>doSomething</i> method is not available inside of the each.</p>
<p><textarea class="js" cols="100" name="code">Ext.each(myArry, function(r){<br />
    this.doSomething(r);<br />
});</textarea></p>
<p>This next code maintains scope within the <i>each</i> loop.</p>
<p><textarea class="js" cols="100" name="code">Ext.each(myArry, function(r){<br />
    this.doSomething(r);<br />
}, this);</textarea></p>
<p>The difference is in the third argument that passes scope to the <i>each</i> loop.</p>
<h2>Events</h2>
<p>Setting up event handlers is another easy place to loose scope, and when the event finally fires off it quickly becomes unclear where the problem originated</p>
<p><textarea class="js" cols="100" name="code">myCmp.on(&#8216;myevent&#8217;, this.myHandler);</textarea></code></p>
<p>This next code maintains scope within the <i>event</i> handler.</p>
<p><textarea class="js" cols="100" name="code">myCmp.on('myevent', this.myHandler, this);</textarea></p>
<p>Just like with the <i>each</i> loop, we are passing in a scope as the third argument</p>
<p><b>NOTE:</b> (thanks <a href="http://rich-waters.com/blog">Rich Waters</a>) this also applies to subscribing to events via the listeners config, for example:</p>
<p><textarea class="js" cols="100" name="code">listeners: {<br />
    myevent: {<br />
        fn: this.myHandler,<br />
        scope: this<br />
    }<br />
}</textarea></p>
<h2>Buttons</h2>
<p>A <i>Buttons</i> handler is scoped to the button component itself by default, so everything inside that handler has a <i>this</i> that references the button. Its not very often that I actually use a buttons handler to manipulate the button itself, so I need my scope somewhere else. Luckily the button config has a <i>scope</i> option.</p>
<p><textarea class="js" cols="100" name="code">buttons: [{<br />
    text: 'Do Something',<br />
    handler: this.doSomething,<br />
    scope: this<br />
}]</textarea></p>
<h2>Message Boxes</h2>
<p>The <i>MessageBox's</i> callback is a similar situation to the <i>Button</i>, so we need to pass it a scope as well, this way we have access to <i>this</i> inside the handler.</p>
<p><textarea class="js" cols="100" name="code">Ext.Msg.prompt(<br />
    'Do Something',<br />
    'Something',<br />
    this.doSomething,<br />
    this<br />
);</textarea></p>
<p>I hope these tips help you out - By paying special attention to these four areas you should be able to minimize those late night scope related debugging sessions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinylfox.com/four-tips-for-staying-on-track-with-scope-in-extjs/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Getting Started With Grid Drag &amp; Drop</title>
		<link>http://www.vinylfox.com/getting-started-with-grid-drag-drop/</link>
		<comments>http://www.vinylfox.com/getting-started-with-grid-drag-drop/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 17:32:27 +0000</pubDate>
		<dc:creator>Shea Frederick</dc:creator>
				<category><![CDATA[ExtJS Tutorials]]></category>
		<category><![CDATA[ExtJS 2.x]]></category>

		<guid isPermaLink="false">http://www.vinylfox.com/?p=113</guid>
		<description><![CDATA[This tutorial builds on the demo code included with the Learning ExtJS book, specifically the 7_json_grid.php example from chapter 5 &#8211; which can also be downloaded here. The code for this tutorial can be downloaded here, and a live example is available here. Were going to implement a fairly simplistic grid drag and drop. This [...]]]></description>
			<content:encoded><![CDATA[<p><b>This tutorial builds on the demo code included with the Learning ExtJS book, specifically the 7_json_grid.php example from chapter 5 &#8211; which can also be <a href="http://code.google.com/p/learning-extjs-book-samples/source/browse/trunk/Chapter5/7_json_grid.php">downloaded here.</a></b></p>
<p>The code for this tutorial can be downloaded <a href="http://www.vinylfox.com/examples/grid-drag-and-drop.zip">here</a>, and a live example is available <a href="http://www.vinylfox.com/examples/grid-drag-and-drop/grid-drag-and-drop.php">here</a>.</p>
<p>Were going to implement a fairly simplistic grid drag and drop. This implementation will allow you to drag a row of data to re-order it within the same grid. We will also play with the look of the <i>dragproxy</i>, which is a visual element used to represent the grid row while its in transition.</p>
<h3>Getting Started</h3>
<p>The first thing we need to do is tell our <i>GridPanel</i> that it&#8217;s going to be used for drag and drop, this is because the default behavior for a grid is to have no drag and drop functionality (which cuts down on resources, ie: memory). We can enable the drag and drop functionality by setting the <i>enableDragDrop</i> config value to <em>true</em></p>
<p><textarea class="js" cols="100" rows="15" name="code">enableDragDrop : true</textarea></p>
<p>Now that the first step is out of the way, lets move on to defining some of our drag and drop specifics.</p>
<h3>D&#038;D Groups</h3>
<p>We will need to set the drag and drop group &#8211; <i>ddGroup</i> &#8211; this is a unique identifier that ExtJS components will use to share their dragged and dropped items. For our example, we are using &#8216;mygrid-dd&#8217;. In your case this might be something more along the lines of &#8216;contacts&#8217; or &#8216;products&#8217; which could be set on multiple components to allow drag and drop between them.</p>
<p><textarea class="js" cols="100" rows="15" name="code">ddGroup : &#8216;mygrid-dd&#8217;,<br />
ddText : &#8216;Place this row.&#8217;,</textarea></p>
<p><a href="http://www.vinylfox.com/wp-content/uploads/2008/12/ddgrid-start.png"><img style="margin-right: 15px;" src="http://www.vinylfox.com/wp-content/uploads/2008/12/ddgrid-start-300x230.png" alt="ddgrid-start" title="ddgrid-start" width="300" height="230" class="alignnone size-medium wp-image-156" border=0 align="left"/></a>Setting those two config options will give us a grid that allows rows to be dragged but not dropped, and has a very generic looking <i>dragproxy</i>. So lets first tackle getting rid of that ugly <i>dragproxy</i> by overwriting it at the start of the selection process. We can do this by adding a <i>beforerowselect</i> listener that will modify the <i>dragproxy</i> message.</p>
<h3>Listening For The Drag</h3>
<p>Using the grids selection model, we can listen for a <i>beforerowselect</i> event and change the <i>dragproxy</i>.</p>
<p><textarea class="js" cols="100" rows="15" name="code">sm: new Ext.grid.RowSelectionModel({<br />
    singleSelect:true,<br />
    listeners: {<br />
        beforerowselect: function(sm,i,ke,row){<br />
            grid.ddText = title_img(row.data.title, null, row);<br />
        }<br />
    }<br />
})</textarea></p>
<p><img style="margin-right: 15px;" src="http://www.vinylfox.com/wp-content/uploads/2009/01/custom-dragproxy.png" alt="custom-dragproxy" title="custom-dragproxy" width="280" height="155" align="left" class="alignleft size-full wp-image-177" />This gives us a much nicer looking <i>dragproxy</i>, but we still have nowhere to drop the row.</p>
<h3>Dropping The Row</h3>
<p>In order to drop a row we need to setup the grids body area as a <i>DropTarget</i>, which will allow it to accept a dropped row.</p>
<p><textarea class="js" cols="100" rows="15" name="code">var ddrow = new Ext.dd.DropTarget(grid.getView().mainBody, {<br />
    ddGroup : &#8216;mygrid-dd&#8217;,<br />
    notifyDrop : function(dd, e, data){<br />
        var sm = grid.getSelectionModel();<br />
        var rows = sm.getSelections();<br />
        var cindex = dd.getDragData(e).rowIndex;<br />
        if (sm.hasSelection()) {<br />
            for (i = 0; i < rows.length; i++) {<br />
                store.remove(store.getById(rows[i].id));<br />
                store.insert(cindex,rows[i]);<br />
            }<br />
            sm.selectRecords(rows);<br />
        }<br />
    }<br />
});</textarea></p>
<p>Just like the <i>GridPanel</i>, one of the first config options we need to set on the <i>DropTarget</i> is the <i>ddGroup</i>, which is set to <i>mygrid-dd</i>. This allows the <i>GridPanel</i> to accept any drops that come from a component having this same <i>ddGroup</i> (of course we are only using one as both source and target). Next we setup the code to be executed when a successful drop happens &#8211; the <i>notifyDrop</i>.</p>
<p>Lets break down the code were executing when a successful drop occurs:</p>
<ol>
<li>Grab a reference to the <i>GridPanel</i>&#8216;s <i>SelectionModel</i>.</li>
<li>Find out what row(s) are selected.</li>
<li>Get the index of where the row was dropped in relation to the other rows.</li>
<li>Loop through the selected rows.</li>
<li>Remove the row of data from its current location.</li>
<li>Add the row of data at its new location.</li>
<li>Select the new row (just for a touch of class)</li>
</ol>
<p>From this bit of code we have a grid that allows you to re-order the rows. If you wanted to update the database with the new order, then an ajax call could be added within the <i>notifyDrop</i> event. We could even use this same basic concept to drag rows between separate grids or other ExtJS components.</p>
<h3>Whats Next?</h3>
<p>There are a few samples in the SDK download that deal with drag and drop, and as always the API documentation has a huge amount of information to help you on your way.</p>
<ul>
<li><a href="http://www.extjs.com/deploy/dev/examples/tree/reorder.html">Reorder Within a Tree</a></li>
<li><a href="http://www.extjs.com/deploy/dev/examples/tree/two-trees.html">Multiple Tree Drag &#038; Drop</a></li>
<li><a href="http://www.extjs.com/deploy/dev/examples/dd/dnd_grid_to_grid.html">Multiple Grid Drag &#038; Drop</a></li>
<li><a href="http://extjs.com/deploy/dev/docs/">API Documentation</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.vinylfox.com/getting-started-with-grid-drag-drop/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Grid Filter Plugin &#8211; Backend Code (in PHP)</title>
		<link>http://www.vinylfox.com/grid-filter-php-backend-code/</link>
		<comments>http://www.vinylfox.com/grid-filter-php-backend-code/#comments</comments>
		<pubDate>Sat, 19 Apr 2008 00:00:34 +0000</pubDate>
		<dc:creator>Shea Frederick</dc:creator>
				<category><![CDATA[ExtJS Tutorials]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://ww2.vinylfox.com/?p=3</guid>
		<description><![CDATA[Ive been using the Grid Filter plugin since it was first released - I just fell in love with it right away, so I thought it would be a nice idea to share with you my back end PHP code that makes the filter grid actually return filtered data. It handles all the types of filtering that the Grid Filter plugin has available.]]></description>
			<content:encoded><![CDATA[<p class="p">The code used for this example is available <a href="http://www.vinylfox.com/extjs/examples/grid-filter.zip">by itself</a>, or as one of the examples in the <a href="http://extjs.com/deploy/dev/examples/grid-filtering/grid-filter.html" target"_blank">ExtJS API download.</a> This code is provided with the intent of showing how to build a filtered query from the Grid Filter Plugin in PHP, therefore it does NOT contain any security precautions. Please modify this script before use in a production environment.</p>
<h3>The Plugin</h3>
<p class="p">If your not familiar with the Grid Filter plugin, I would suggest checking out the ExtJS User Extension and Plugins <a href="http://extjs.com/forum/showthread.php?t=14503">forum thread on this plugin</a>. ExtJS has decided to include my PHP script in the example code released with their 2.1 API download, which I think is a great idea, since the question of how exactly to make this grid filtering work seems to come up very often.</p>
<h3>The General Concept</h3>
<p>There are five data types that can be filtered, and each of them has their own specific options.</p>
<ul>
<li>string</li>
<li>list</li>
<li>boolean</li>
<li>numeric</li>
<li>date</li>
</ul>
<p class="p">All the info needed to filter a column is passed by the filter grid plugin as a single &#8216;filter&#8217; post variable that essentially is a multi-dimentional array.</p>
<p class="p">Each filtered column passes three values, and in some cases a fourth.</p>
<ul>
<li>type</li>
<li>value</li>
<li>field</li>
<li>comparison (only for date or numeric &#8211; ne, eq, gt, lt)</li>
</ul>
<p class="p">This ends up making the post variable look something like this &#8211; with two filters.</p>
<pre style="color:#000000">
	 filter[0][data][type] : list
	filter[0][data][value] : small,medium
	      filter[0][field] : size
	 filter[1][data][type] : boolean
	filter[1][data][value] : true
	      filter[1][field] : visible</pre>
<p class="p">The predictable format of post variables makes it easy to code the server side PHP for this.</p>
<h3>The Code</h3>
<p><textarea name="code" class="php" rows="15" cols="100"><br />
$where = &#8221; 0 = 0 &#8220;;<br />
if (is_array($filter)) {<br />
	for ($i=0;$i<count($filter);$i++){<br />
		switch($filter[$i]['data']['type']){<br />
			case &#8216;string&#8217; : $qs .= &#8221; AND &#8220;.$filter[$i]['field'].&#8221; LIKE &#8216;%&#8221;.$filter[$i]['data']['value'].&#8221;%&#8217;&#8221;; Break;<br />
			case &#8216;list&#8217; :<br />
				if (strstr($filter[$i]['data']['value'],&#8217;,')){<br />
					$fi = explode(&#8216;,&#8217;,$filter[$i]['data']['value']);<br />
					for ($q=0;$q<count($fi);$q++){<br />
						$fi[$q] = &#8220;&#8216;&#8221;.$fi[$q].&#8221;&#8216;&#8221;;<br />
					}<br />
					$filter[$i]['data']['value'] = implode(&#8216;,&#8217;,$fi);<br />
					$qs .= &#8221; AND &#8220;.$filter[$i]['field'].&#8221; IN (&#8220;.$filter[$i]['data']['value'].&#8221;)&#8221;;<br />
				}else{<br />
					$qs .= &#8221; AND &#8220;.$filter[$i]['field'].&#8221; = &#8216;&#8221;.$filter[$i]['data']['value'].&#8221;&#8216;&#8221;;<br />
				}<br />
			Break;<br />
			case &#8216;boolean&#8217; : $qs .= &#8221; AND &#8220;.$filter[$i]['field'].&#8221; = &#8220;.($filter[$i]['data']['value']); Break;<br />
			case &#8216;numeric&#8217; :<br />
				switch ($filter[$i]['data']['comparison']) {<br />
					case &#8216;ne&#8217; : $qs .= &#8221; AND &#8220;.$filter[$i]['field'].&#8221; != &#8220;.$filter[$i]['data']['value']; Break;<br />
					case &#8216;eq&#8217; : $qs .= &#8221; AND &#8220;.$filter[$i]['field'].&#8221; = &#8220;.$filter[$i]['data']['value']; Break;<br />
					case &#8216;lt&#8217; : $qs .= &#8221; AND &#8220;.$filter[$i]['field'].&#8221; < ".$filter[$i]['data']['value']; Break;<br />
					case &#8216;gt&#8217; : $qs .= &#8221; AND &#8220;.$filter[$i]['field'].&#8221; > &#8220;.$filter[$i]['data']['value']; Break;<br />
				}<br />
			Break;<br />
			case &#8216;date&#8217; :<br />
				switch ($filter[$i]['data']['comparison']) {<br />
					case &#8216;ne&#8217; : $qs .= &#8221; AND &#8220;.$filter[$i]['field'].&#8221; != &#8216;&#8221;.date(&#8216;Y-m-d&#8217;,strtotime($filter[$i]['data']['value'])).&#8221;&#8216;&#8221;; Break;<br />
					case &#8216;eq&#8217; : $qs .= &#8221; AND &#8220;.$filter[$i]['field'].&#8221; = &#8216;&#8221;.date(&#8216;Y-m-d&#8217;,strtotime($filter[$i]['data']['value'])).&#8221;&#8216;&#8221;; Break;<br />
					case &#8216;lt&#8217; : $qs .= &#8221; AND &#8220;.$filter[$i]['field'].&#8221; < '".date('Y-m-d',strtotime($filter[$i]['data']['value']))."'"; Break;<br />
					case &#8216;gt&#8217; : $qs .= &#8221; AND &#8220;.$filter[$i]['field'].&#8221; > &#8216;&#8221;.date(&#8216;Y-m-d&#8217;,strtotime($filter[$i]['data']['value'])).&#8221;&#8216;&#8221;; Break;<br />
				}<br />
			Break;<br />
		}<br />
	}<br />
	$where .= $qs;<br />
}<br />
$query = &#8220;SELECT * FROM demo WHERE &#8220;.$where;<br />
</textarea></p>
<p class="p">This simple bit of code is all we need on the server side to have a fully filterable set of data.</p>
<p class="p"><a href="http://www.extjs.com/deploy/dev/examples/grid-filtering/grid-filter-local.html">See it in action here (switch &#8216;Local Filtering&#8217; off)</a></p>
<p class="p">UPDATE &#8211; 5/28 : Added support for &#8216;ne&#8217; (not equals) on numeric and date fields.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinylfox.com/grid-filter-php-backend-code/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Adding a Google Map to a Tab or Window</title>
		<link>http://www.vinylfox.com/window-tab-google-map/</link>
		<comments>http://www.vinylfox.com/window-tab-google-map/#comments</comments>
		<pubDate>Mon, 26 Nov 2007 00:03:22 +0000</pubDate>
		<dc:creator>Shea Frederick</dc:creator>
				<category><![CDATA[ExtJS Tutorials]]></category>
		<category><![CDATA[Google Maps]]></category>

		<guid isPermaLink="false">http://ww2.vinylfox.com/?p=5</guid>
		<description><![CDATA[Short tutorial on how to have a google map appear within a window, or a tab.]]></description>
			<content:encoded><![CDATA[<p class="p">
		The code used for this example is available <a href="http://www.vinylfox.com/extjs/examples/window-tab-google-map.zip">here</a>. Working examples can be found <a href="http://www.vinylfox.com/extjs/examples/window-tab-google-map/">here</a>.
	</p>
<h3>Getting Started</h3>
<p class="p">
		 If you havent yet used the Google Maps API, then I would suggest going through some of their examples prior to this. I will assume that you already have knowledge of how the Google Maps API works.
	</p>
<p class="p">
		 Sadly, its quite easy if you already know what the Google Maps API needs, and what Ext provides. Getting to this point took me a few evenings of goofing with it. A Google Map initialization expects to be passed a DOM object, like what you would get from <i>getElementById(&#8216;bla&#8217;)</i>, and Ext provides this with <i>Ext.get(&#8216;bla&#8217;).dom</i>. This changes slightly when your using a tab or window, because you want your map to render in the body area of the tab/window, Ext provides <i>body.dom</i> for these situations.
	</p>
<p class="p">
		The window and Tab need to be rendered before you can gain access to the <i>body.dom</i> element, for this I just tag a <i>show()</i> in the end when they are being created.
	</p>
<h3>Tabs</h3>
<p><textarea name="code" class="js" rows="15" cols="100"><br />
var tabs = new Ext.TabPanel({<br />
	renderTo: &#8216;tabs&#8217;,<br />
	width:450,<br />
	height: 300,<br />
	frame:true<br />
});<br />
var tab1 = tabs.add({id: &#8216;gmap&#8217;,title: &#8216;Map Tab&#8217;,html: &#8216;map&#8217;,tbar: [<br />
	'Address',<br />
	addr_field = new Ext.form.TextField({<br />
		width:200,<br />
		qtip:'Example: 123 Fake Street, Baltimore, MD, 21211, US'<br />
	})<br />
]}).show();<br />
var tab2 = tabs.add({title: &#8216;Some Other Tab&#8217;});<br />
map = new GMap2(tab1.body.dom);<br />
</textarea></p>
<h3>Windows</h3>
<p><textarea name="code" class="js" rows="15" cols="100"><br />
dialog = new Ext.Window({<br />
	title: &#8216;Google Map in a Window&#8217;,<br />
	width:535,<br />
	height:500,<br />
	shadow:true,<br />
	closeAction: &#8216;hide&#8217;,<br />
	buttons: [<br />
		{<br />
			text:'Map Address',<br />
			handler: function(){ Map.addressPrompt(); }<br />
		},<br />
		{<br />
			text:'Close',<br />
			handler: function(){ dialog.hide(); }<br />
		}<br />
	]<br />
}).show();<br />
map = new GMap2(dialog.body.dom);<br />
</textarea></p>
<p class="p">
	The last line of each of these sniplets is the important part, it gives the Google Maps API access to the proper DOM element. Its just that simple, and when I figured it out, I was kicking myself.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinylfox.com/window-tab-google-map/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Populate a ComboBox from a DataStore (JSON)</title>
		<link>http://www.vinylfox.com/forms-combobox-datastore/</link>
		<comments>http://www.vinylfox.com/forms-combobox-datastore/#comments</comments>
		<pubDate>Sat, 29 Sep 2007 03:22:25 +0000</pubDate>
		<dc:creator>Shea Frederick</dc:creator>
				<category><![CDATA[ExtJS Tutorials]]></category>
		<category><![CDATA[ExtJS 1.x]]></category>

		<guid isPermaLink="false">http://ww2.vinylfox.com/?p=39</guid>
		<description><![CDATA[This tutorial gets you started with using a database driven ComboBox. ]]></description>
			<content:encoded><![CDATA[<p class="p">
		I would suggest downloading the code used for this example <a href="http://www.vinylfox.com/extjs/examples/forms-combobox-datastore.zip">here</a> so you have something to work with. Working examples can be found <a href="http://www.vinylfox.com/extjs/examples/forms-combobox-datastore/">here</a>.
	</p>
<h3>Getting Started</h3>
<p class="p">
		 The <i>ComboBox</i> is always a very usefull form field type, and populating it dynamically makes it even more usefull. We will just be creating a basic <i>ComboBox</i> thats populated from a JSON data source which pulls data from our database.
	</p>
<h3>Setup The Reader</h3>
<p class="p">
		As with any data source, we will need to setup the reader so our data store knows how to read the JSON data were retreiving. We can pass an empty config object to <i>JsonReader</i> since were just populating a simple <i>ComboBox</i> and the second argument is a very simple record definition.
	</p>
<p><textarea name="code" class="js" rows="15" cols="100"><br />
	var rd_random_employee_data = new Ext.data.JsonReader({}, [ 'id', 'name']);<br />
</textarea></p>
<h3>Setup The Data Store</h3>
<p class="p">
		The data source uses a standard store, which by default reads JSON formatted data.
	</p>
<p><textarea name="code" class="js" rows="15" cols="100"><br />
	var ds_random_employee_data_active = new Ext.data.Store({<br />
	    proxy: new Ext.data.HttpProxy({<br />
			// this json data contains only employees where active is &#8216;true&#8217;<br />
	        url: &#8216;forms-combobox-data.php?active=true&#8217;<br />
	    }),<br />
	    reader: rd_random_employee_data,<br />
		remoteSort: false<br />
	});<br />
</textarea></p>
<h3>The ComboBox</h3>
<p class="p">
	Now we just specify the store in our ComboBox instantiation code and set the displayField and hiddenName (which should be different from the name, if specified).</p>
<p><textarea name="code" class="js" rows="15" cols="100"><br />
	var random_employees_active = new Ext.form.ComboBox({<br />
		fieldLabel: &#8216;Active Random Employee Data&#8217;,<br />
		store: ds_random_employee_data_active,<br />
		valueField: &#8216;id&#8217;,<br />
		displayField: &#8216;name&#8217;,<br />
		hiddenName: &#8216;active_id&#8217;,<br />
		mode: &#8216;remote&#8217;,<br />
		minChars : 0<br />
	});<br />
</textarea></p>
<p class="p">
	Setting the minChars to zero and the mode to &#8216;remote&#8217; will make sure that the data is fetched each time the combo is clicked or focused.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinylfox.com/forms-combobox-datastore/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Domhelper/DomQuery fun with Forms</title>
		<link>http://www.vinylfox.com/domhelper-fun-with-forms/</link>
		<comments>http://www.vinylfox.com/domhelper-fun-with-forms/#comments</comments>
		<pubDate>Thu, 19 Jul 2007 00:04:19 +0000</pubDate>
		<dc:creator>Shea Frederick</dc:creator>
				<category><![CDATA[ExtJS Tutorials]]></category>
		<category><![CDATA[ExtJS 1.x]]></category>

		<guid isPermaLink="false">http://ww2.vinylfox.com/?p=7</guid>
		<description><![CDATA[This tutorial uses domhelper and domquery to tweak forms. ]]></description>
			<content:encoded><![CDATA[<p class="p">I would suggest downloading the code used for this example <a href="http://www.vinylfox.com/extjs/examples/domhelper-fun-with-forms.zip">here</a> so you have something to work with. Working examples can be found <a href="http://www.vinylfox.com/extjs/examples/domhelper-fun-with-forms/">here</a>.</p>
<h3>Getting Started</h3>
<p class="p"><em>DomHelper</em> is a very powerful tool, so were going to start with some simple things, and you can take it from there. We are going to be using the <em>insertAfter</em> and <em>insertBefore</em> methods of <em>DomHelper</em> in the following examples.</p>
<h3>Spacing form Elements</h3>
<p class="p">For this example we are adding a spacer div that will bump the next form element down enough to make it line up with a form element in another column <span id="img-a">(see image)</span>. The first argument to <em>insertAfter</em> is the dom element, allot of the time you can use something simple to retrieve the dom element, such as <em>Ext.get(&#8216;bla&#8217;)</em>. In our case, were going to use <em>DomQuery</em> to find our dom element since were modifying dynamic forms.</p>
<p><textarea class="js" cols="100" rows="15" name="code">Ext.DomHelper.insertAfter(<br />
 	Ext.DomQuery.selectNode(&#8216;input[name="last"]&#8216;),<br />
 	{<br />
 		tag: &#8216;div&#8217;,<br />
 		&#8216;style&#8217;: &#8216;width:180px;height:48px;&#8217;<br />
 	},<br />
 	false<br />
);</textarea></p>
<h3>Adding More Radio Buttons</h3>
<p class="p">In this one we will add a second radio button to allow the form to have two options on the same line <span id="img-b">(see image)</span>. First the actual radio button is added, then its label is added.</p>
<p><textarea class="js" cols="100" rows="15" name="code">Ext.DomHelper.insertAfter(<br />
 	Ext.DomQuery.selectNode(&#8216;label:contains(Male)&#8217;),<br />
 	{<br />
 		tag: &#8216;input&#8217;,<br />
 		id: &#8216;gender2&#8242;,<br />
 		type: &#8216;radio&#8217;,<br />
 		name: &#8216;gender&#8217;,<br />
 		&#8216;class&#8217;: &#8216;x-form-radio x-form-field&#8217;<br />
 	},<br />
 	false<br />
);<br />
Ext.DomHelper.insertAfter(<br />
 	Ext.get(&#8216;gender2&#8242;),<br />
 	{<br />
 		tag: &#8216;label&#8217;,<br />
 		&#8216;class&#8217;: &#8216;x-form-cb-label&#8217;,<br />
 		&#8216;for&#8217;: &#8216;gender2&#8242;,<br />
 		html: &#8216;Female&#8217;<br />
 	},<br />
 	false<br />
);</textarea></p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinylfox.com/domhelper-fun-with-forms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

