Wish List
Tags
adobe air ajax coldfusion examples ext flex javascript max2007 misc technology ui
Recent Entries
Search
RSS
Subscribe
Coldfusion 8's CFGRID
One of the tags to receive an upgrade in CF8 is the CFGRID tag. I can honestly say that I have never had a need to use this tag in the past although for some I can see that it 'could' have been useful.
The added support comes in the form of: type="html",bind,bindOnLoad,pageSize,prefesrbPageOnSort,stripeRows,stripeRowColor.
Lets focus for a minute on the new bind attribute. This attribute allows you to specify an expression to fill the grids contents. This expression can come in three flavors: You can bind directly to a CFC, a javascript function, or additionaly a URL.
The old restriction on the cfgrid is still in place, that being that it has to live within the bounds of a CFFORM tag, that's a small price to pay for ajax functionality right?
So here is a code snippet of the cfgrid in action:
<cfgrid format="html" name="grid_Tables" pagesize="7" selectmode="row"
bind="cfc:components.artgallery.artist.getArtists({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})">
<cfgridcolumn name="ARTISTID" display="No"/>
<cfgridcolumn name="FIRSTNAME" header="FIRSTNAME" >
<cfgridcolumn name="LASTNAME" header="LASTNAME" >
<cfgridcolumn name="CITY" header="CITY" >
<cfgridcolumn name="STATE" header="STATE" >
</cfgrid>
</cfform>
</cfoutput>
Nothing too fancy other than the bind right? lets look at that a little closer.
Here is what it looks like using the default styling:

You should immediately notice the bar at the bottom. This additional little functionality provides automatic paging of your data and you set that by specifiying the pageSize attribute. This value is automatically passed onto your cfc as well.
Lets take a quick look at the code for the Artist cfc:
<cfargument name="page" required="yes">
<cfargument name="pageSize" required="yes">
<cfargument name="gridsortcolumn" required="yes">
<cfargument name="gridsortdirection" required="yes">
<cfquery name="members" datasource="cfartgallery">
SELECT ARTISTID, FIRSTNAME, LASTNAME, CITY, STATE
FROM ARTISTS
<cfif gridsortcolumn neq ''>
order by #gridsortcolumn# #gridsortdirection#
</cfif>
</cfquery>
<cfreturn queryconvertforgrid(members,page,pagesize)/>
</cffunction>
Nothing new here, or is there? Well if you spotted the queryconvertforgrid function as new you are right, its nothing I built, its a new function desiged specifically for converting a query into something that the cfgrid can use, it also takes the page, and pagesize attributes as arguments so it only passes back the specific page needed.
Another thing, if you have firebug installed you will be able to see how the call is made to your cfc. For my example I left out the argument collection: http://localhost/mycf/components/artgallery/artist.cfc?method=getArtists&returnFormat=json&argumentCollection=
for binding to CFC's coldfusion automatically appends the argument pair "returnFormat=json" this ensures that what you get back is a valid json dataset.
There is a lot more you can do with the cfgrid and a bit of javascript coding, you could use the
You could quite easily set up master/deatail pages using ajax calls to get the data and update a detail form on the same page. And then update the data asynchronously and then at the same time automatically refresh the grid, pretty darn cool!
In future posts I will explore setting up a master detail form and creating editable grids, and exploring some of the other new features of Coldfusion 8


you clicked on one of the column headers.
Sorry at the moment it is not possible to create custom renderers for cfgrid. It may be possible if you manipulate the base ext.grid objects column model after Coldfusion writes the code.
Your best choice is to use the ext grid. I have a tutorial on ext grid with custom renderer: http://www.garyrgilbert.com/blog/index.cfm/2007/7/...
Thanks for the info Hal. I didn't think to add the img tag directly in the query. I guess as you say you can display just about anything in the grid. I was more thinking in the lines of having a cell renderer not formulating html on the server-side and sending it to the front end.
if i call the method directory from the cfml file, no problem, but once I try to use binding, it cannot find the cfc.
any ideas?
can you get to your cfc using a url? for example I have a cfc in webroot\dev\com\gg called fileExplorer.cfc and to access the getDirectories method in the cfc I can use the URL below
http://www.garyrgilbert.com/dev/com/gg/fileexplore...=
which returns a result to me in a json array.
The bind attribute would therefore look like "cfc:dev.com.gg.fileExplorer.getDirectories({cftreeitempath},{cftreeitemvalue})"
As a side note you can NOT use a cf mapping your cfc MUST be web accessible!
Any help?
Thanks in advance.
In order to do that you would bind the grid to the onchange event of the cfselect. To do that you would change the bind expression on your grid.
<cfselect name="myselect" bind="cfc:mycfc.getSelectData()" bindonload="true">
<cfgrid ..... bind="cfc:mycfc.getGridData({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection},{myselect})"
This will automatically tie your grid to the value field of your select.
http://www.garyrgilbert.com/blog/index.cfm/2007/11...