<?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 1.x</title>
	<atom:link href="http://www.vinylfox.com/tag/extjs-1x/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>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>
		<item>
		<title>Loading Data Into &amp; Submitting a Form</title>
		<link>http://www.vinylfox.com/forms-submit/</link>
		<comments>http://www.vinylfox.com/forms-submit/#comments</comments>
		<pubDate>Wed, 23 May 2007 00:47:57 +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=36</guid>
		<description><![CDATA[We will go through the full circle of using forms, from populating the form with data from the server, to submitting that data back to the server. The backend I use is PHP and MySQL, however this tutorial is not specific to PHP and MySQL and only requires that you have a way to read and output JSON data on your server.]]></description>
			<content:encoded><![CDATA[<p>
		This tutorial uses the employee edit form used in the getting started tutorial, if you are not yet familiar with creating a form then you should start with the <a href="http://www.extjs.com/tutorial/getting-started-forms">getting started tutorial</a>.
	</p>
<p>
		I would suggest downloading the <a href="http://www.vinylfox.com/extjs/examples/forms-submit.zip">code used for this<br />
example</a> so you have something to work with. You can also find a</p>
<p><a href="http://www.vinylfox.com/extjs/examples/forms-submit/forms-submit-working.php">working example</a>.
	</p>
<p>
		We will go through the full circle of using forms, from populating the form with data from the server, to submitting that data back to the server. The backend I use is PHP and MySQL, however this tutorial is not specific to PHP and MySQL and only requires that you have a way to read and output JSON data on your server.
	</p>
<h3>Let&#8217;s Get Started</h3>
<p>
		We first need to set our form&#8217;s <i>url</i>, which is a php script that will take POST data and write it to our database.
	</p>
<p><textarea name="code" class="js" rows="15" cols="100"><br />
var form_employee = new Ext.form.Form({<br />
	&#8230;<br />
	url:&#8217;forms-submit-process.php&#8217;,<br />
	&#8230;<br />
});<br />
</textarea></p>
<p>
		Our data consist of five fields, <i>id</i>, <i>name</i>, <i>title</i>, <i>hire_date</i> and <i>active</i>, which will be retreived and placed into a data store.
	</p>
<p>
		The following code sets up the data store, at this point no data has been retrieved. Our proxy references a php script that retrieves row id 14 from our database and formats it as a JSON string.
	</p>
<p><textarea name="code" class="js" rows="15" cols="100"><br />
employee_data = new Ext.data.Store({<br />
	proxy: new Ext.data.HttpProxy({url: &#8216;forms-submit-getdata.php?id=14&#8242;}),<br />
	reader: new Ext.data.JsonReader({},<br />
		[ 'id', 'name', 'title', 'hire_date', 'active']<br />
	),<br />
	remoteSort: false<br />
});<br />
</textarea></p>
<p>
		The next thing to do is setup our event listener to watch for when the data loads, this ensures that we don&#8217;t populate the form before the data has been loaded.
	</p>
<p><textarea name="code" class="js" rows="15" cols="100"><br />
employee_data.on(&#8216;load&#8217;, function() {</p>
<p>	// data loaded, do something with it here&#8230; </p>
<p>});</p>
<p></textarea></p>
<p>
		When that data is loaded we can take it and populate the form fields using <i>setValue</i>. Here we are using <i>getAt(0)</i> to retrieve the first row of data (row zero) from our data store.
	</p>
<p>NOTE: the form and form fields used here are defined and explained in the <a href="http://www.extjs.com/tutorial/getting-started-forms">getting started tutorial</a>.</p>
<p><textarea name="code" class="js" rows="15" cols="100"><br />
	employee_name.setValue(employee_data.getAt(0).data.name);<br />
	employee_title.setValue(employee_data.getAt(0).data.title);<br />
	employee_hire_date.setValue(employee_data.getAt(0).data.hire_date);<br />
	employee_active.setValue(<br />
		Ext.util.Format.boolean(employee_data.getAt(0).data.active)<br />
	);<br />
</textarea></p>
<p>We will also want to create our submit button and render the form, remembering to set extra parameters to pass along with our POST data from the form fields. You will find it useful to pass a row identifier (id) so the php script knows which row to update in the database, along with an <i>action</i> just for good measure.</p>
<p>I&#8217;m also using <i>isValid</i> to make sure the form conforms to each field&#8217;s requirements before submitting.</p>
<p><textarea name="code" class="js" rows="15" cols="100"><br />
	form_employee.addButton(&#8216;Save&#8217;, function(){<br />
		if (form_employee.isValid()) {<br />
			form_employee.submit({<br />
				params:{<br />
					action:&#8217;submit&#8217;,<br />
					id:employee_data.getAt(0).data.id<br />
				},<br />
				waitMsg:&#8217;Saving&#8230;&#8217;<br />
			});<br />
		}else{<br />
			Ext.MessageBox.alert(&#8216;Errors&#8217;, &#8216;Please fix the errors noted.&#8217;);<br />
		}<br />
	}, form_employee);</p>
<p>	form_employee.render(&#8216;employee-form&#8217;);<br />
</textarea></p>
<h3>Loading Our Data</h3>
<p>
		Now we <i>load</i> the data.
	</p>
<p><textarea name="code" class="js" rows="15" cols="100"><br />
employee_data.load();<br />
</textarea></p>
<p>
		It really can be just that easy to create a working Ext form with an amazing level of usability right out of the box. We have some server side scripts that retrieve and format data from our database, and write that data back to our database. These server side scripts can be as simple as a few lines.
	</p>
<h3>What&#8217;s Next?</h3>
<p>
    	As always, the API documentation and examples are a great way to learn how to tweak this form to fit your needs.
    </p>
<ul>
<li><a href="http://extjs.com/docs/">API Documentation</a></li>
<li><a href="http://extjs.com/forum/">Community Forums</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.vinylfox.com/forms-submit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Grid &#8211; Basics of Paging</title>
		<link>http://www.vinylfox.com/grid-paging/</link>
		<comments>http://www.vinylfox.com/grid-paging/#comments</comments>
		<pubDate>Mon, 02 Apr 2007 03:46:54 +0000</pubDate>
		<dc:creator>Shea Frederick</dc:creator>
				<category><![CDATA[ExtJS Tutorials]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ExtJS 1.x]]></category>

		<guid isPermaLink="false">http://ww2.vinylfox.com/?p=46</guid>
		<description><![CDATA[This tutorial walks you through adding paging to your grid. ]]></description>
			<content:encoded><![CDATA[<p>I would suggest downloading the code used for this example <a href="/yui-ext/examples/grid-paging/">here</a> so you have something to work with. A working example can be found <a href="/yui-ext/examples/grid-paging/grid-paging-working.php">here</a>.</p>
<h3>Grid Data</h3>
<p>A paging grid must have a server side element to perform the breaking up of data into pages.</p>
<p>For this example we are using php as the server side language, and a MySQL database with some randomly generated data. The PHP script below is used to retrieve our data and break it up into pages using the <i>limit</i> and <i>start</i> variables that are passed from the paging toolbar.</p>
<p>
<textarea name="code" class="php" rows="15" cols="100"><br />
$link = mysql_pconnect(&#8220;test-db.vinylfox.com&#8221;, &#8220;test&#8221;, &#8220;testuser&#8221;)<br />
	or die(&#8220;Could not connect&#8221;);<br />
mysql_select_db(&#8220;test&#8221;) or die(&#8220;Could not select database&#8221;);</p>
<p>$sql_count = &#8220;SELECT id, name, title, hire_date, active FROM random_employee_data&#8221;;<br />
$sql = $sql_count . &#8221; LIMIT &#8220;.$_GET['start'].&#8221;, &#8220;.$_GET['limit'];</p>
<p>$rs_count = mysql_query($sql_count);</p>
<p>$rows = mysql_num_rows($rs_count);</p>
<p>$rs = mysql_query($sql);</p>
<p>while($obj = mysql_fetch_object($rs))<br />
{<br />
	$arr[] = $obj;<br />
}</p>
<p>Echo $_GET['callback'].&#8217;({&#8220;total&#8221;:&#8221;&#8216;.$rows.&#8217;&#8221;,&#8221;results&#8221;:&#8217;.json_encode($arr).&#8217;})&#8217;; </p>
<p></textarea></p>
<p>Were not going to dig much into the server side code, since it can vary quite a bit for each developers needs and environment.</p>
<h3>Whats Needed to Make a Paged Grid?</h3>
<p>NOTE: The example uses <i>ScriptTagProxy</i> only because the data resides on a different server from the example code. In most cases you will be pulling data from the same server the code resides on and using <i>HttpProxy</i>.</p>
<p>The only difference in the data Store is the addition of a <i>totalProperty</i> declaration. In our example, we use &#8216;total&#8217; which is coming from our server side script with the value for the total number of rows we had before breaking them up into pages.</p>
<p>
<textarea name="code" class="js" rows="15" cols="100"><br />
    var ds = new Ext.data.Store({</p>
<p>        proxy: new Ext.data.ScriptTagProxy({<br />
            url: &#8216;http://www.vinylfox.com/yui-ext/examples/grid-paging/grid-paging-data.php&#8217;<br />
        }),</p>
<p>        reader: new Ext.data.JsonReader({<br />
            root: &#8216;results&#8217;,<br />
            totalProperty: &#8216;total&#8217;,<br />
            id: &#8216;id&#8217;<br />
        }, [<br />
            {name: 'employee_name', mapping: 'name'},<br />
            {name: 'job_title', mapping: 'title'},<br />
            {name: 'hire_date', mapping: 'hire_date', type: 'date', dateFormat: 'm-d-Y'},<br />
            {name: 'is_active', mapping: 'active'}<br />
        ])</p>
<p>    });<br />
</textarea>
</p>
<h3>The Paging Bar</h3>
<p>Adding a paging toolbar to the bottom of the grid pane, and your almost done.</p>
<p>
<textarea name="code" class="js" rows="15" cols="100"><br />
    var gridFoot = grid.getView().getFooterPanel(true);</p>
<p>    var paging = new Ext.PagingToolbar(gridFoot, ds, {<br />
        pageSize: 25,<br />
        displayInfo: true,<br />
        displayMsg: &#8216;Displaying results {0} &#8211; {1} of {2}&#8217;,<br />
        emptyMsg: &#8220;No results to display&#8221;<br />
    });<br />
</textarea>
</p>
<p>The last step is to pass the initial <i>start</i> and <i>limit</i> parameters to your data load.</p>
<p>
<textarea name="code" class="js" rows="15" cols="100"><br />
	ds.load({params:{start:0, limit:25}});<br />
</textarea>
</p>
<p>A large portion of the time spent setting up paging is going to be your server side environment that handles passing data back and forth with the grid, once you have that in place the task of adding paging to a grid can be very simple.</p>
<h2>The Final Product</h2>
<h4>grid-paging.js</h4>
<p>
<textarea name="code" class="js" rows="15" cols="100"><br />
Ext.onReady(function(){</p>
<p>    var ds = new Ext.data.Store({<br />
		// HttpProxy should be used here<br />
        proxy: new Ext.data.ScriptTagProxy({<br />
            url: &#8216;http://www.vinylfox.com/yui-ext/examples/grid-paging/grid-paging-data.php&#8217;<br />
        }),</p>
<p>        reader: new Ext.data.JsonReader({<br />
            root: &#8216;results&#8217;,<br />
            totalProperty: &#8216;total&#8217;,<br />
            id: &#8216;id&#8217;<br />
        }, [<br />
            {name: 'employee_name', mapping: 'name'},<br />
            {name: 'job_title', mapping: 'title'},<br />
            {name: 'hire_date', mapping: 'hire_date', type: 'date', dateFormat: 'm-d-Y'},<br />
            {name: 'is_active', mapping: 'active'}<br />
        ])</p>
<p>    });</p>
<p>    var cm = new Ext.grid.ColumnModel([{<br />
		   id: 'name',<br />
           header: "Name",<br />
           dataIndex: 'employee_name',<br />
           width: 100<br />
        },{<br />
           header: "Title",<br />
           dataIndex: 'job_title',<br />
           width: 170<br />
        },{<br />
           header: "Hire Date",<br />
           dataIndex: 'hire_date',<br />
           width: 70,<br />
		   renderer: Ext.util.Format.dateRenderer('n/j/Y')<br />
        },{<br />
           header: "Active",<br />
           dataIndex: 'is_active',<br />
           width: 50<br />
        }]);</p>
<p>    var grid = new Ext.grid.Grid(&#8216;grid-paging&#8217;, {<br />
        ds: ds,<br />
        cm: cm,<br />
		autoExpandColumn: &#8216;name&#8217;<br />
    });</p>
<p>    grid.render();</p>
<p>    var gridFoot = grid.getView().getFooterPanel(true);</p>
<p>    var paging = new Ext.PagingToolbar(gridFoot, ds, {<br />
        pageSize: 25,<br />
        displayInfo: true,<br />
        displayMsg: &#8216;Displaying results {0} &#8211; {1} of {2}&#8217;,<br />
        emptyMsg: &#8220;No results to display&#8221;<br />
    });</p>
<p>    ds.load({params:{start:0, limit:25}});</p>
<p>});<br />
</textarea></p>
<h4>grid-paging-working.php</h4>
<p><textarea name="code" class="xml" rows="15" cols="100"><br />
<html><br />
	<head></p>
<link rel="stylesheet" type="text/css" href="/lib/resources/css/ext-all.css" />
		<script type="text/javascript" src="/lib/yui-utilities.js"></script><br />
		<script type="text/javascript" src="/lib/ext-yui-adapter.js"></script><br />
		<script type="text/javascript" src="/lib/ext-all-debug.js"></script></p>
<p>		<script type="text/javascript" src="grid-paging.js"></script></p>
<p>	</head><br />
	<body></p>
<div id="grid-paging" style="border:1px solid #99bbe8;overflow: hidden; width: 665px; height: 300px;"></div>
<p>	</body><br />
</html><br />
</textarea></p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinylfox.com/grid-paging/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Template &#8211; Getting Started</title>
		<link>http://www.vinylfox.com/template-getting-started/</link>
		<comments>http://www.vinylfox.com/template-getting-started/#comments</comments>
		<pubDate>Sat, 03 Mar 2007 03:23:36 +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=38</guid>
		<description><![CDATA[This tutorial walks you through using the template functionality to do some basic data formatting. ]]></description>
			<content:encoded><![CDATA[<p>I would suggest downloading the code used for this example <a href="/yui-ext/examples/template-getting-started/">here</a> so you have something to work with. A working example can be found <a href="/yui-ext/examples/template-getting-started/template-getting-started-working.php">here</a>.</p>
<h3>Step 1, HTML for Your Template</h3>
<p>The first step is pretty straight forward, its the HTML that will be used to format your data. Some keywords in curly brackets will be the placeholders for your data {id}, {url} and {text}. You could simplify this by using {0}, {1}, {2}, but naming your placeholders makes the code more readable.</p>
<p>Now we load the html template we just created into a template object (line 5), then compile the template for speed (line 6). Compiling the template is not required, but generally improves the speed.</p>
<p>
<textarea name="code" class="js:firstline[3]" rows="15" cols="100"><br />
	var html = &#8216;<a id="{id}" href="{url}" class="nav">{text}</a><br />&#8216;;</p>
<p>	var tpl = new Ext.Template(html);<br />
	tpl.compile();<br />
</textarea>
</p>
<h3>Step 2, Adding Data to Your Template</h3>
<p>In this next step we are going to append two rows to our data using the append method, as you can see the elements &#8216;id&#8217;, &#8216;url&#8217; and &#8216;text&#8217; correspond with placeholders in our template above.
<p>
<textarea name="code" class="js:firstline[8]" rows="15" cols="100"><br />
	tpl.append(&#8216;blog-roll&#8217;, {<br />
	    id: &#8216;link1&#8242;,<br />
	    url: &#8216;http://www.jackslocum.com/&#8217;,<br />
	    text: &#8220;Jack&#8217;s Site&#8221;<br />
	});<br />
	tpl.append(&#8216;blog-roll&#8217;, {<br />
	    id: &#8216;link2&#8242;,<br />
	    url: &#8216;http://www.extjs.com/&#8217;,<br />
	    text: &#8220;Jack&#8217;s New Site&#8221;<br />
	});<br />
</textarea>
</p>
<p>Thats the basics of using the template, pretty simple, eh? </p>
<h2>The Final Product</h2>
<h4>template-getting-started.js</h4>
<p>
<textarea name="code" class="js" rows="15" cols="100"><br />
Ext.onReady(function(){</p>
<p>    var html = &#8216;<a id="{id}" href="{url}" class="nav">{text}</a><br />&#8216;;</p>
<p>	var tpl = new Ext.Template(html);<br />
	tpl.compile();</p>
<p>	tpl.append(&#8216;blog-roll&#8217;, {<br />
	    id: &#8216;link1&#8242;,<br />
	    url: &#8216;http://www.jackslocum.com/&#8217;,<br />
	    text: &#8220;Jack&#8217;s Site&#8221;<br />
	});<br />
	tpl.append(&#8216;blog-roll&#8217;, {<br />
	    id: &#8216;link2&#8242;,<br />
	    url: &#8216;http://www.extjs.com/&#8217;,<br />
	    text: &#8220;Jack&#8217;s New Site&#8221;<br />
	});</p>
<p>});<br />
</textarea></p>
<h4>template-getting-started-working.php</h4>
<p>
<textarea name="code" class="xml" rows="15" cols="100"><br />
<html><br />
	<head><br />
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></p>
<link rel="stylesheet" href="/lib/resources/css/ext-all.css" />
		<script src="/lib/yui-utilities.js"></script><br />
		<script src="/lib/ext-yui-adapter.js"></script><br />
		<script src="/lib/ext-all.js"></script><br />
		<script type="text/javascript" src="template-getting-started.js"></script><br />
	</head><br />
	<body></p>
<div id="blog-roll" class="ygrid-mso"></div>
<p>	</body><br />
</html></p>
<p></textarea></p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinylfox.com/template-getting-started/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Grid &#8211; Getting Started</title>
		<link>http://www.vinylfox.com/grid-getting-started/</link>
		<comments>http://www.vinylfox.com/grid-getting-started/#comments</comments>
		<pubDate>Fri, 02 Mar 2007 03:32:42 +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=44</guid>
		<description><![CDATA[This tutorial walks you through using a grid with XML as the data source.]]></description>
			<content:encoded><![CDATA[<p>I would suggest downloading the code used for this example <a href="/yui-ext/examples/grid-getting-started/">here</a> so you have something to work with. A working example can be found <a href="/yui-ext/examples/grid-getting-started/grid-getting-started-working.php">here</a>.</p>
<h3>Step 1, Data Definition</h3>
<p>First we need to tell the grid what XML element defines each row of data, in this case its named &#8216;Item&#8217; as you can see from the sample XML below.</p>
<h3>Single Row of XML Sample Data</h3>
<p>
<textarea name="code" class="xml" rows="15" cols="100"><br />
<Item><br />
	<ASIN>0446613657</ASIN><br />
	<DetailPageURL>http://www.amazon[*SNIP*]JVQEG2</DetailPageURL><br />
	<ItemAttributes><br />
		<Author>Sidney Sheldon</Author><br />
		<Manufacturer>Warner Books</Manufacturer><br />
		<ProductGroup>Book</ProductGroup><br />
		<Title>Are You Afraid of the Dark?</Title><br />
	</ItemAttributes><br />
</Item><br />
</textarea></p>
<p>Set the <i>record</i> in your schema definition (line 8 of the sample code below) to &#8216;Item&#8217; so it coresponds to a row in our XML data.</p>
<p>Then we need to define which collumn contains the unique <i>id</i>entifier by setting the &#8216;id&#8217; (line 9 of the sample code below). In our sample data this is the &#8216;ASIN&#8217; collumn.</p>
<p>The last part of our data definition are the fields you want to display (line 11 of our sample code). This is just an array with the field names. Make sure these correspond with the element names in your XML data and place them in the order you want the collumns displayed in your grid, they dont need to be in the same order they are found in the XML file.</p>
<p>
<textarea name="code" class="js:firstline[3]" rows="15" cols="100"><br />
    var dataStore = new Ext.data.Store({</p>
<p>        proxy: new Ext.data.HttpProxy({url: &#8216;sampledata-sheldon.xml&#8217;}),</p>
<p>        reader: new Ext.data.XmlReader({<br />
               record: &#8216;Item&#8217;,<br />
               id: &#8216;ASIN&#8217;<br />
           }, [<br />
               'Author', 'Title', 'Manufacturer', 'ProductGroup'<br />
           ])<br />
    });<br />
</textarea>
</p>
<h3>Step 2, Collumn Model</h3>
<p>The next step would be defining the <i>Collumn Model</i>, which simply means setting up some properties for the collumns that determine how they are displayed and treated. This is an array containing configuration parameters for each collumn given in the order of the collumns as defined in the data definitions &#8220;fields&#8221; array from the previous step.</p>
<p>Probably the most common configuration variables are going to be <i>header</i> and <i>width</i>, so you will want to make sure to declare atleast those two, however width is not required and can be taken care of using the autoWidth/Height functions later on.</p>
<h3>Sample Collumn Model</h3>
<p>
<textarea name="code" class="js:firstline[16]" rows="15" cols="100"><br />
	var colModel = new Ext.grid.ColumnModel([<br />
		{header: "Author", width: 120, dataIndex: 'Author'},<br />
		{header: "Title", width: 180, dataIndex: 'Title'},<br />
		{header: "Manufacturer", width: 115, dataIndex: 'Manufacturer'},<br />
		{header: "Product Group", width: 100, dataIndex: 'ProductGroup'}<br />
	]);<br />
</textarea>
</p>
<p>The last thing we do is to pass the Grid the data store and collumn model (lines 22-25), render the grid, then load in the data from our data store. Thats really all you need to get your grid up and working.</p>
<h3>Render it!</h3>
<p>
<textarea name="code" class="js:firstline[22]" rows="15" cols="100"><br />
    var grid = new Ext.grid.Grid(&#8216;mygrid&#8217;, {<br />
        ds: dataStore,<br />
        cm: colModel<br />
    });<br />
    grid.render();</p>
<p>    dataStore.load();<br />
</textarea>
</p>
<h2>The Final Product</h2>
<h4>grid-getting-started.js</h4>
<p>
<textarea name="code" class="js" rows="15" cols="100"><br />
Ext.onReady(function(){</p>
<p>    var dataStore = new Ext.data.Store({</p>
<p>        proxy: new Ext.data.HttpProxy({url: &#8216;sampledata-sheldon.xml&#8217;}),</p>
<p>        reader: new Ext.data.XmlReader({<br />
               record: &#8216;Item&#8217;,<br />
               id: &#8216;ASIN&#8217;<br />
           }, [<br />
               'Author', 'Title', 'Manufacturer', 'ProductGroup'<br />
           ])<br />
    });</p>
<p>    var colModel = new Ext.grid.ColumnModel([<br />
	    {header: "Author", width: 120, dataIndex: 'Author'},<br />
		{header: "Title", width: 180, dataIndex: 'Title'},<br />
		{header: "Manufacturer", width: 115, dataIndex: 'Manufacturer'},<br />
		{header: "Product Group", width: 100, dataIndex: 'ProductGroup'}<br />
	]);</p>
<p>    var grid = new Ext.grid.Grid(&#8216;mygrid&#8217;, {<br />
        ds: dataStore,<br />
        cm: colModel<br />
    });<br />
    grid.render();</p>
<p>    dataStore.load();<br />
});<br />
</textarea></p>
<h4>grid-getting-started-working.php</h4>
<p>
<textarea name="code" class="xml" rows="15" cols="100"><br />
<html><br />
	<head><br />
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></p>
<link rel="stylesheet" href="/lib/resources/css/ext-all.css" />
		<script src="/lib/yui-utilities.js"></script><br />
		<script src="/lib/ext-yui-adapter.js"></script><br />
		<script src="/lib/ext-all.js"></script><br />
		<script type="text/javascript" src="grid-getting-started.js"></script><br />
	</head><br />
	<body></p>
<div id="mygrid" class="ygrid-mso"></div>
<p>	</body><br />
</html><br />
</textarea></p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinylfox.com/grid-getting-started/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

