<?xml version="1.0" encoding="utf-8"?>
			
			<rss version="2.0">
			<channel>
			<title>Objective Action - Ext JS</title>
			<link>http://www.objectiveaction.com/Kevin/index.cfm</link>
			<description>An Objective Look at Adobe and the Internet</description>
			<language>en-us</language>
			<pubDate>Wed, 08 Sep 2010 13:07:46+0100</pubDate>
			<lastBuildDate>Fri, 26 Dec 2008 16:18:00+0100</lastBuildDate>
			<generator>BlogCFC</generator>
			<docs>http://blogs.law.harvard.edu/tech/rss</docs>
			<managingEditor>kevin@objectiveinternet.com</managingEditor>
			<webMaster>kevin@objectiveinternet.com</webMaster>
			
			
			
			
			
			<item>
				<title>Using Ext JS 2.2 Ajax in CF - Part 4 - Color Picker and Date Picker Controls.</title>
				<link>http://www.objectiveaction.com/Kevin/index.cfm/2008/12/26/Using-Ext-JS-22-Ajax-in-CF--Part-4--Color-Picker-and-Date-Picker-Controls</link>
				<description>
				
				One of the big reasons for using Ext JS with ColdFusion is the ability to use the widgets to improve the user interface we present to our users. Ext JS comes aith a Date picker and a Color Picker and the &lt;a href=&quot;http://www.madfellas.com/docs/&quot; target=&quot;_blank&quot;&gt;ColdExt tags demo&lt;/a&gt; has both tantalising us in its demo pages. Unfortunately the ColdExt demos don&apos;t 
really show us how to use them in a real application. In the most simple case we might want a form to show one of these controls and for the user to be able to submit the form with the chosen date or color value.

Lets take a look at the example code for the color palette:

&lt;code&gt;
&lt;!--- all examples will be appended to this div ---&gt;
&lt;div id=&quot;progress1-out&quot; class=&quot;output&quot;&gt;&lt;/div&gt;

&lt;ext:onReady&gt;  
   
	&lt;ext:createChild tag=&quot;h2&quot; renderTo=&quot;progress1-out&quot;&gt;Color Palette&lt;/ext:createChild&gt;  
	&lt;ext:colorPalette var=&quot;myPalette&quot; renderTo=&quot;progress1-out&quot;&gt;  
....
&lt;/ext:onReady&gt;

&lt;/code&gt;

Unfortnately this code does not show how we can use the code in a form. All the Ext JS controls are based on an event model. When we add a control to page with the ColdExt tags it won&apos;t do anything unless we add some Javascript to react to the events that happen to the control.

A quick look at the &lt;a href=&quot;http://extjs.com/deploy/dev/docs/&quot; target=&quot;_blank&quot;&gt;Ext JS 2.2 API&lt;/a&gt; reveals that there are a number of events that we can create listeners for.

The one that looked most interesting for me wass the select event which fires when a color is selected and passes the control and the selected color as parameters. To make use of this we can create another control to save the value which can then be submitted by the form. In this simple case I have created an Ext textField control to save the selected value. I populate it with the color value when the user clicks on a color in the palette.

So here is my new example code whit a listener, which looks for the &apos;select&apos; event and updates the textField in the code below:

&lt;code&gt;
&lt;!--- all examples will be appended to this div ---&gt;
&lt;div id=&quot;progress1-out&quot; class=&quot;output&quot;&gt;&lt;/div&gt;

&lt;ext:onReady&gt;
	&lt;ext:createChild tag=&quot;h2&quot; renderTo=&quot;progress1-out&quot;&gt;Color Palette&lt;/ext:createChild&gt;
	&lt;ext:colorPalette var=&quot;myPalette&quot; renderTo=&quot;progress1-out&quot;&gt;
		&lt;ext:listener eventName=&quot;select&quot;&gt;
			function(control,value){
				Ext.getCmp(&quot;color&quot;).setValue(value);
			}
		&lt;/ext:listener&gt;
	&lt;/ext:colorPalette&gt;

	&lt;ext:textField id=&quot;color&quot; name=&quot;color&quot; label=&quot;Color&quot; value=&quot;&quot; renderTo=&quot;progress1-out&quot;/&gt;

....

&lt;/ext:onReady&gt;
&lt;/code&gt;

A similar piece of code can be used for the date picker:

&lt;code&gt;
&lt;ext:onReady&gt;
	&lt;ext:createChild tag=&quot;h2&quot; renderTo=&quot;progress1-out&quot;&gt;Date Picker&lt;/ext:createChild&gt;
	&lt;ext:datePicker var=&quot;myDatePicker&quot; renderTo=&quot;progress1-out&quot;&gt;
		&lt;ext:listener eventName=&quot;select&quot;&gt;
			function(control,value){
				Ext.getCmp(&quot;date&quot;).setValue(value);
			}
		&lt;/ext:listener&gt;
	&lt;/ext:datePicker&gt;
	
	&lt;ext:textField id=&quot;date&quot; name=&quot;date&quot; label=&quot;Date&quot; value=&quot;&quot; renderTo=&quot;progress1-out&quot;/&gt;

&lt;/ext:onReady&gt;
&lt;/code&gt;

Of course, in a real example, the textField would be most likely to be inside a form tag and would not then require the renderTo attribute.

I hope this has been useful to you. If so please leave a note in the comments.
				
				</description>
						
				
				<category>Ext JS</category>				
				
				<category>AJAX</category>				
				
				<pubDate>Fri, 26 Dec 2008 16:18:00+0100</pubDate>
				<guid>http://www.objectiveaction.com/Kevin/index.cfm/2008/12/26/Using-Ext-JS-22-Ajax-in-CF--Part-4--Color-Picker-and-Date-Picker-Controls</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>Using Ext JS 2.2 Ajax in CF - Part 3 - Adding new rows to the grid.</title>
				<link>http://www.objectiveaction.com/Kevin/index.cfm/2008/12/24/Using-Ext-JS-22-Ajax-in-CF--Part-3--Adding-new-rows-to-the-grid</link>
				<description>
				
				Welcome to my third visit into the world of Ext JS and the ColdExt tag library.

To put this post in context I have included a picture of my final grid control at the top of the page.

When I began trying to use the Ext Grid Control to edit records, one of the first problems I had to solve was how to add additional rows. I asked the question on the ColdExt forum but got no answer.

Luckilly there were lots of people who had solved the problem on the Ext JS forums before me. It took me a while to translate the Ext JS solutions into one based on ColdExt, but here is what I came up with.

Several of the Ext JS widgets make use of the Ext.Data.Store this is a general purpose way to store data on the client and can keep trach of changes in the background leaving the control to get on with the display and presentation of the data. The Store also provides ways to transfer the data to and from the server. 

One particular version of the store is JsonStore which provides a way to read and populate the store from Json data which is easy to create with ColdFusion. In the ColdExt examples Justin Carter has used a &lt;a href=&quot;http://www.epiphantastic.com/cfjson/&quot;&gt;Json library by Jehiah Czebotar and Thomas Messier&lt;/a&gt; to create the Json which is used to load the store. In his notes Justin says this is &quot;for compatibility&quot;. I know CF8 will create Json directly so I am not sure where the compatibility issue lies. It could be done to allow CF7 users to make use of the ColdExt tags or it could be because of some difference between the way CF8 creates Json and what is needed by the Ext Js widgets. Maybe someone who knows will comment.

So the first set in using the Grid as an editor is to create a suitable data store. Here is my code for that:

&lt;code&gt;
&lt;ext:jsonStore var=&quot;ObjectTypeJSON&quot; autoLoad=&quot;true&quot; remoteSort=&quot;true&quot;
			root=&quot;query.data&quot; totalProperty=&quot;totalcount&quot; url=&quot;/model/mProperty/ObjectTypeGetJson.cfm&quot;&gt;
		
	&lt;ext:field name=&quot;objecttypeid&quot; /&gt;
	&lt;ext:field name=&quot;groupid&quot; /&gt;
	&lt;ext:field name=&quot;visibilityid&quot; /&gt;
	&lt;ext:field name=&quot;managementid&quot; /&gt;
	&lt;ext:field name=&quot;title&quot; /&gt;
	&lt;ext:field name=&quot;description&quot; /&gt;
	&lt;ext:field name=&quot;allowmultiple&quot; /&gt;
	&lt;ext:field name=&quot;groupmayown&quot; /&gt;
	&lt;ext:field name=&quot;membermayown&quot; /&gt;
	&lt;ext:field name=&quot;membermayedit&quot; /&gt;
		
	&lt;ext:param name=&quot;limit&quot; value=&quot;#attributes._Maxrows#&quot; /&gt;
	&lt;ext:param name=&quot;deleted&quot; value=&quot;&quot; /&gt;
	&lt;ext:param name=&quot;selectedRow&quot; value=&quot;&quot; /&gt;
	
&lt;/ext:jsonStore&gt;
&lt;/code&gt;

The url parameter on the JsonStore tag links to my ColdFusion template that creates the Json data.

I have created fields for each of the columns I display in the grid and I also created a couple of extra param tags which I use to keep track of which row is selcted and a list of the rows which have been deleted.

The limit param is used to drive the paging toolbar which allows the user to page through a large dataset a few rows at a time without having to download all the rows to the client.

So our goal is to create a new record and display it in the grid, where the user can update it with their own data. In order to do that all that is needed is to add the new record to the store. Ext JS will take care of the rest.

To add a new record we need to first create a record template:

&lt;code&gt;

	// Create a record type to allow new ones to be created.
	var ObjectType = Ext.data.Record.create([
		{name: &apos;objecttypeid&apos;, type: &apos;number&apos;},
		{name: &apos;groupid&apos;, type: &apos;number&apos;},
		{name: &apos;visibilityid&apos;, type: &apos;number&apos;},
		{name: &apos;managementid&apos;, type: &apos;number&apos;},
		{name: &apos;title&apos;, type: &apos;string&apos;},
		{name: &apos;description&apos;, type: &apos;string&apos;},
		{name: &apos;allowmultiple&apos;, type: &apos;bool&apos;},
		{name: &apos;groupmayown&apos;, type: &apos;bool&apos;},
		{name: &apos;membermayown&apos;, type: &apos;bool&apos;},
		{name: &apos;membermayedit&apos;, type: &apos;bool&apos;}
		
	]);

&lt;/code&gt;

When we have a tempate for a record we can create one:

&lt;code&gt;	
	// Create a new empty record.
	var newRec = new ObjectType({
		objecttypeid: 0,
		groupid: #attributes.grou_select#,
		visibilityid: 5,
		managementid: 5,
		title: &apos;&apos;,
		description: &apos;&apos;,
		allowmultiple: true,
		groupmayown: false,
		membermayown: true,
		membermayedit: true
	});

&lt;/code&gt;

Finally we add the record to the store:

&lt;code&gt;
	// Turn editing off and add the record.
	myGrid.stopEditing();
	myGrid.getStore().insert(0, newRec);
	myGrid.startEditing(0, 0);
	
&lt;/code&gt;

In order to use the above code in a coldExt control we simply have to specify it as the handler for the button on the toolbar. We wrap the handler code in a pair of handler tags.

&lt;code&gt;

&lt;ext:handler name=&quot;addNew&quot;&gt;&lt;/ext:handler&gt;

&lt;/code&gt;
Finally we link the code to the button on the toolbar:

&lt;code&gt;
&lt;ext:toolbarButton text=&quot;Add New&quot; iconCls=&quot;icon-add&quot; handler=&quot;addNew&quot; /&gt;

&lt;/code&gt;

Well I hope that is some use to someone. Please let me know if it helps you.
				
				</description>
						
				
				<category>Ext JS</category>				
				
				<category>AJAX</category>				
				
				<pubDate>Wed, 24 Dec 2008 16:49:00+0100</pubDate>
				<guid>http://www.objectiveaction.com/Kevin/index.cfm/2008/12/24/Using-Ext-JS-22-Ajax-in-CF--Part-3--Adding-new-rows-to-the-grid</guid>
				
				<enclosure url="http://www.objectiveaction.com/Kevin/enclosures/ExtGridExample.png" length="7366" type="image/png"/>
				
			</item>
			
		 	
			
			
			<item>
				<title>Using Ext JS 2.2 Ajax in CF - Part 2 - Combo boxes in the grid.</title>
				<link>http://www.objectiveaction.com/Kevin/index.cfm/2008/12/19/Using-Ext-JS-22-Ajax-in-CF--Part-2--Combo-boxes-in-the-grid</link>
				<description>
				
				The real reason I started looking at Ext was my frustration with the Ext based grid control in ColdFusion 8. As I mentioned in &lt;a href=&quot;/index.cfm/2008/12/17/Using-Ext-JS-22-Ajax-in-CF--Part-1--Coldext-plus-Combo-box-Id-and-Value&quot;&gt;the previous post&lt;/a&gt;, I have never had much sucess with the &amp;lt;cfgrid&amp;gt; tag. It seems to offer so much but deliver so little. When it comes down to the final page its always gone in favour of somthing much more clunky but which actually works. 

Flush with my sucess with combo boxes in an Ext form. I was convinced that I could move on to the real goal. The Ext Grid control. This seemed to offer everything I wanted. The &lt;a href=&quot;http://www.madfellas.com/docs/&quot; target=&quot;_blank&quot;&gt;examples&lt;/a&gt; showed all the needed features and with the support of the &lt;a href=&quot;http://coldext.riaforge.org/&quot; target=&quot;_blank&quot;&gt;ColdExt tags&lt;/a&gt; I showed no fear.

Well I was soon caught out by the same issue that got me earlier. How to make the combo box do what a select list does. The Ext grid has the same problem with combo boxes as regular forms. However I could not see how to make use of my earlier fix, the use of a hidden field.

There were a &lt;a href=&quot;http://extjs.com/forum/showthread.php?t=27784&quot; target=&quot;_blank&quot;&gt;number of postings&lt;/a&gt; on the &lt;a href=&quot;
http://extjs.com/forum/showthread.php?t=34691&quot; target=&quot;_blank&quot;&gt;Ext Forums&lt;/a&gt;, with various solutions, none of which appeared to work for me.

I decided to pick &lt;a href=&quot;http://extjs.com/forum/showthread.php?p=165242&quot;&gt;a forum posting by nkohari&lt;/a&gt; and worry it until I got somewhere. At first it seemed completly incompatible with the ColdExt tags, so I began with using the Javascript and not using any ColdExt tags.

What was missing from that posting took a little time to discover.

&lt;code&gt;
var store = new Ext.data.SimpleStore({
  fields: [ &quot;value&quot;, &quot;text&quot; ],
  data: [
    [ &quot;value1&quot;, &quot;Option 1&quot; ],
    [ &quot;value2&quot;, &quot;Option 2&quot; ],
    ...
  ]
});

var combo = new Ext.form.ComboBox({
  store: store,
  valueField: &quot;value&quot;,
  displayField: &quot;text&quot;,
  ...
});
&lt;/code&gt;

Its all in the ... that nkohari adds to the parameters. After a little worrying and changing things I had a working drop down but it was trying to get somthing remotely when all the data was local. Further investigation revealed that the ColdExt tags add mode: &quot;local&quot; where the ... is in the combo definition. Added that and it all worked!

When I looked at the final code I began to realise that there was a way to make most of it work using ColdExt tags.

The main issue is that the renderer has to have a combo box passed to it as a parameter so you have to define your combo boxes before you build the grid rather than inside the grid as normal.

So my final solution uses the script from nkohari to build the renderer and the rest is done with ColdExt:

&lt;code&gt;
&lt;ext:onReady&gt;
	&lt;!--- Code to fix the combo box in a grid prolem in Ext Grids ---&gt;
	&lt;ext:script&gt;
		Ext.namespace(&quot;Ext.ux&quot;);
		Ext.ux.comboBoxRenderer = function(combo) {
		  return function(value) {
		    var idx = combo.store.find(combo.valueField, value);
		    var rec = combo.store.getAt(idx);
		    return rec.get(combo.displayField);
		  };
		}
	&lt;/ext:script&gt;
	&lt;!--- Define the combo box ---&gt;
	&lt;ext:comboBox var=&quot;managementCombo&quot; valueField=&quot;value&quot; displayField=&quot;text&quot; allowBlank=&quot;false&quot; &gt;
		&lt;cfloop query=&quot;qManagement&quot;&gt;&lt;ext:option value=&quot;#qManagement.mana_id#&quot;&gt;#qManagement.mana_title#&lt;/ext:option&gt;
		&lt;/cfloop&gt;
	&lt;/ext:comboBox&gt;
&lt;/code&gt;

Inside the grid we simply use the predefined combo box and our renderer.

&lt;code&gt;
&lt;ext:gridColumn header=&quot;Editable By&quot; width=&quot;90&quot; sortable=&quot;true&quot; dataIndex=&quot;managementid&quot; hidden=&quot;#hide#&quot;
									renderer=&quot;Ext.ux.comboBoxRenderer(managementCombo)&quot; editor=&quot;managementCombo&quot; /&gt;
&lt;/code&gt;


I hope that helps someone else use the Ext Grid without the hassle I had. Please let me know if it helps you.
				
				</description>
						
				
				<category>Ext JS</category>				
				
				<category>AJAX</category>				
				
				<pubDate>Fri, 19 Dec 2008 10:07:00+0100</pubDate>
				<guid>http://www.objectiveaction.com/Kevin/index.cfm/2008/12/19/Using-Ext-JS-22-Ajax-in-CF--Part-2--Combo-boxes-in-the-grid</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>Using Ext JS 2.2 Ajax in CF - Part 1 - Coldext plus Combo box Id and Value</title>
				<link>http://www.objectiveaction.com/Kevin/index.cfm/2008/12/17/Using-Ext-JS-22-Ajax-in-CF--Part-1--Coldext-plus-Combo-box-Id-and-Value</link>
				<description>
				
				Over the last couple of weeks I have been playing with a new Ajax library. New? Well its been around a while but it is new to me.

The reason for my interest was the frustration I had with using the grid in ColdFusion. The cfgrid tag is very appealing but every time I tried to use it, something I needed did not work quite well enough or quite the way I wanted in order to make it suitable for the application. It has always been very frustrating. The latest CF8 implementation is no better. I realised that the thing I was working on would be best done with some kind of grid. I started with a cfgrid tag and soon realised that my idea would not quite work.

Then I remembered that the latest CF8 HTML grid uses Ext 1.0 as its underlying engine. I took a quick look at the &lt;a 
href=&quot;http://extjs.com/&quot; target=&quot;_blank&quot;&gt;Ext web site&lt;/a&gt; and the &lt;a href=&quot;http://extjs.com/deploy/dev/examples/samples.html&quot; target=&quot;_blank&quot;&gt;grid demo&lt;/a&gt;.

When I tried the samples I saw immediately that the latest version of Ext would do what I needed. Basicly I wanted to be able to easily page through a number of records and the examples had a way of adding a paging toolbar and a toolbar with icons for save and refresh and so on.

The only problem for me was that my exiting application code was using some other ColdFusion features that were based on Ext. I realised that using two different versions of Ext together would impossible so I had to replace all the existing easy to use CF tab based stuff with Ext code which is based on Javascript. It was do-able but not vey nice.

Luckily before I began the job I thought to check RIAforge and found that Justin Carter had created a &lt;a href=&quot;http://coldext.riaforge.org/&quot; target=&quot;_blank&quot;&gt;series of CF custom tags&lt;/a&gt; to support the Ext 2.2 libary. Basicly each tag exacly mimics the JS call so that you can write a CF tag instead of the JS code.

For me this made the conversion much easier. No need to reformat everything just change some of the tags to call Justin&apos;s tags and it worked! A big thank you to Justin for the tag library.

Since then I have come across some issues with the way Ext JS things work and found work arounds. Some of them are not quite sraightforward, I decided to document my solutions so that anyone else who wants can avoid going through the hassle.

So here is my first contribution....

&lt;h2&gt;Combo box Id and Value&lt;/h2&gt;

At first sight the Ext JS combo box seems to be exacly like an HTML select. There is a dropdown list, you can choose somthing from the list and it gets displayed. Simple? Wrong!

The combo box is actually a more complex control and although it can look a bit like a select it is actually a completely new beast to those who have grown up using HTML. In the default mode the combo box does one major thing that the select does not and that is it allows you to type a new thing into the box that is not just one of the items in the drop down. This is the key to the reson why it does not work like a select control. 

While the select control allows you to choose a value and  returns the id associated with that value the combo can&apos;t quite do that. Because you can type somthing it has to return what is displayed. After all it might just be something not actually in the dropdown list.

You can set the contol so that it does not allow typing by setting a parameter, (editable=&quot;false&quot;), but that won&apos;t make the control return the id rather than the value. On the Ext Js web site there are some complex solutions offered with cuson renderers for the combo box, but somehow they don&apos;t feel easy to implement.

What I decided to do was to create a hidden control and use that for the id. When someone updates the choice, a change event can be used to update the hidden contol. Here is an example written using the coldext tags.

&lt;code&gt;

&lt;ext:comboBox name=&quot;naxg_marketing_text&quot; label=&quot;Enquiry Source&quot; value=&quot;#attributes.naxg_marketing#&quot; emptyText=&quot;Select an Enquiry Source...&quot; allowBlank=&quot;false&quot; editable=&quot;false&quot;&gt;
	&lt;cfloop query=&quot;qMarketing&quot;&gt;&lt;ext:option value=&quot;#qMarketing.sour_id#&quot;&gt;#qMarketing.sour_title#&lt;/ext:option&gt;
	&lt;/cfloop&gt;
	&lt;ext:listener eventName=&quot;change&quot;&gt;
				function(control,newValue,oldvalue){
			Ext.getCmp(&quot;naxg_marketing&quot;).setValue(newValue);
				}
	&lt;/ext:listener&gt;
&lt;/ext:comboBox&gt;
&lt;ext:hidden id=&quot;naxg_marketing&quot; name=&quot;naxg_marketing&quot; value=&quot;#attributes.naxg_marketing#&quot; /&gt;
					
&lt;/code&gt;

I hope you find it useful. Please let me know if you do.
				
				</description>
						
				
				<category>Ext JS</category>				
				
				<category>AJAX</category>				
				
				<pubDate>Wed, 17 Dec 2008 13:21:00+0100</pubDate>
				<guid>http://www.objectiveaction.com/Kevin/index.cfm/2008/12/17/Using-Ext-JS-22-Ajax-in-CF--Part-1--Coldext-plus-Combo-box-Id-and-Value</guid>
				
			</item>
			
		 	
			</channel></rss>