Using Ext JS 2.2 Ajax in CF - Part 2 - Combo boxes in the grid.

The real reason I started looking at Ext was my frustration with the Ext based grid control in ColdFusion 8. As I mentioned in the previous post, I have never had much sucess with the <cfgrid> 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 examples showed all the needed features and with the support of the ColdExt tags 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 number of postings on the Ext Forums, with various solutions, none of which appeared to work for me.

I decided to pick a forum posting by nkohari 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.

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

var combo = new Ext.form.ComboBox({
store: store,
valueField: "value",
displayField: "text",
...
});

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: "local" 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:

<ext:onReady>
   <!--- Code to fix the combo box in a grid prolem in Ext Grids --->
   <ext:script>
      Ext.namespace("Ext.ux");
      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);
       };
      }
   </ext:script>
   <!--- Define the combo box --->
   <ext:comboBox var="managementCombo" valueField="value" displayField="text" allowBlank="false" >
      <cfloop query="qManagement"><ext:option value="#qManagement.mana_id#">#qManagement.mana_title#</ext:option>
      </cfloop>
   </ext:comboBox>

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

<ext:gridColumn header="Editable By" width="90" sortable="true" dataIndex="managementid" hidden="#hide#"
                           renderer="Ext.ux.comboBoxRenderer(managementCombo)" editor="managementCombo" />

I hope that helps someone else use the Ext Grid without the hassle I had. Please let me know if it helps you.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Sebastiaan's Gravatar Hi, thanx for these posts.

I cannot believe though that CF should be based on such a flimsy JS-library with so many flaws. To really be able to make use of the power of a JS-framework, Adobe should offer the regular updates, a la updates to Firefox, Opera, OpenOffice, etc.

I think Yahoo or JQuery would be a better choice for Centaur (CF9), and then coupled with frequent updates. Then we won't ahve to do the things you provide such good examples for ;-)
# Posted By Sebastiaan | 12/19/08 12:20 PM
Kevin Roche's Gravatar I was really hoping that they would offer more updates during the life of CF8 especially to the Ajax code. I was disappointed to see no Ajax update in CF 8.0.1.

By the way I think some of the CF8 Ajax is based on Yahoo Libraries.
# Posted By Kevin Roche | 12/19/08 12:52 PM
Steve 'Cutter' Blades's Gravatar I can ultimately see why those update haven't been that quick though. CF would have to rewrite all of the underlying Java classes that they use for building things out, and there were many core architecture changes between Ext JS 1.1 and 2.0, so it really wasn't a 'drop it in' type of scenario.

As has always been the case with cfform, the feature is really geared towards those who are just learning or those who are doing rapid app prototyping. A full scale enterprise implementation has almost always been something that the developer has had to hand code, so that they have full control of implementation.
# Posted By Steve 'Cutter' Blades | 12/19/08 5:59 PM
Claude's Gravatar @Sebastiian's Drive-by shooting: "I cannot believe though that CF should be based on such a flimsy JS-library with so many flaws."

Care to elaborate on the flaws in Ext-JS? And jQuery doesn't include any components, so how do you compare them?
# Posted By Claude | 12/21/08 11:16 PM
Sebastiaan's Gravatar There are so many good JS-frameworks out there, and Ext-JS has come so much further than the version delivered in CF8...
That coupled with the inability or fear of updating the core elements of the Ajax stuff in CFForm makes me NOT use them.
I tend to only make use of CFTextarea and then couple it to the newest version of FCKEditor at all times.

JQuery just feels better, gets more press and blogposts - but feeling is a hard thing to challenge ;-)
# Posted By Sebastiaan | 12/22/08 7:55 AM
Claude's Gravatar My point is that the libraries are completely different. jQuery's strength, if not its main focus, is in its selector engine and method chaining. Ext-JS is a well thought out framework with a complete set of components, which give a developer the ability to build consistent looking applications.

For the record, I use both.
# Posted By Claude | 12/22/08 8:05 AM
Kevin Roche's Gravatar One thing I noticed is that there are good and bad points about both the JS frameworks I have tried. (Only spry and Ext JS so far). I intend to try JQuery but have not had a chance to do that yet. I am thinking of holding a meeting on three different frameowrks at the TVCFUG. Anyone interesting in presenting JQuery?
# Posted By Kevin Roche | 12/23/08 8:24 PM
Claude's Gravatar Kevin, I don't mind presenting jQuery. Let me know what topics you'd like to cover, basics or advanced techniques and when you'd like to do this.
# Posted By Claude | 1/6/09 1:50 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.