ColdFusion 8: Demo of CFGRID, Ajax binding, and CFWINDOW
So I plan to spend time later on talking more about the Ajax work in ColdFusion 8, but I thought I'd share a demo I whipped up for Ben a few weeks back. This demo integrates with Yahoo's Traffic service using my CFYahoo library. Simply enter a zip, hit Go, and the grid will populate with traffic data. When you select a row, I then use a map to show you information about the traffic hot spot.
All of the "magic" can be seen in one line:
<cfinput type="text" name="zip" />
<cfgrid name="reportsGrid" format="html" pageSize="5" stripeRows="true" bind="cfc:yahooProxy.getTraffic({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection},{zip})">
The bind attribute tells ColdFusion to speak to my CFC and use the results for the data.
The code is available below. To run this, be sure to download the CFYahoo package first. And yes - I was trying to be artsy with my design here. Normally I'm not allowed to design anything. ;)
And yes - I hope to have everything up and running on CF8 here soon.
Comments
Nice stuff. But......tried it out, and I'm getting
ColdFusion.Grid.Refresh is not a function in the onclick of the button. What am I missing?
ColdFusion is not defined
[Break on this error] ColdFusion.Ajax.importTag('CFWINDOW');
h127424.cf8beta.c... (line 43)
ColdFusion is not defined
[Break on this error] ColdFusion.Ajax.importTag('CFFORM');
h127424.cf8beta.c... (line 47)
ColdFusion is not defined
[Break on this error] ColdFusion.Ajax.importTag('CFGRID');
h127424.cf8beta.c... (line 65)
ColdFusion is not defined
[Break on this error] ColdFusion.objectCache['reportsGrid'] = new ColdFusion.Grid.Actions('CFGRID11...
h127424.cf8beta.c... (line 69)
ColdFusion is not defined
[Break on this error] };ColdFusion.Event.registerOnLoad(_cf_bind_init_1180671087207);
h127424.cf8beta.c... (line 87)
ColdFusion is not defined
[Break on this error] };ColdFusion.Event.registerOnLoad(_cf_window_init_1180671087208);
I have tried 90502 - but it is not returning any records :-)
I don't seem to be getting any errors.
Do I need my own key/licence?
Thx
Andrew
More specifically, I have a user grid that I want to do 2 things on... the email column is clickable just as a mailto: with the email address in it and the Person's name column clicks through to the edit page and passes "person_id=" and append the value from the hidden person_id column... the best I could do was getting it to do gridkey= but I'd like to not have to change my edit code and I'd also like to be able to make different columns pass different or even multiple url variables. Am I out of luck or is there a way to actually do this?
Our existing plain vanilla grid does something like this (stripped down to basics):
<cfoutput query="theQuery">
<tr><td><a href="index.cfm?myid=#theQuery.myid#&otherid=#theQuery.otherid#">#theQuery.name#</a></td></tr>
</cfoutput>
And I'd like to do something similar with the grid. I'd also like to be able to do a mailto link.
I tried doing something like href="index.cfm?myid={personGrid.myid}" and href="mailto:{personGrid.email}" but that didn't work :)
you can probably do something like(untested): <cfajaxproxy bind="javascript:window.location.href='index.cfm?otherid='+{FormName:GridName.otherid};">
Also, with the Ext object you can write a javascript functions to do all kinds of cool stuff. here is an example of how to edit the data in a cell, save it to your db via a cfc call, and refresh the row in the grid without having to reload all the data in the grid with ColdFusion.Grid.refresh and loose your selected row.
http://www.coldfusionguy.com/ColdFusion/blog/index...
To ensure your data is formatted correctly in an HTML CFGrid, you can apply a custom renderer to the column via javascript. Ray gives an example of a currency renderer here.
http://www.coldfusionjedi.com/index.cfm/2007/8/20/...
I have an example of a custom date renderer here:
http://www.coldfusionguy.com/ColdFusion/blog/index...
Theoretically, you could make a javascript function to format the data in any way you like.
I am using cfwindow and cfgrid, all works beautifully in firefox, but in IE I get an
"Error: Unexpected call to method or property access"
the line that is references is
this.form.appendChild(this.editField);
After much frustration it seems that it is when the cfgrid is html, and I need it to be html because I an using the bind attribute for some nice ajax.
Also found that if it isn't in cfwindow then it works fine. So something with cfwindow and cfgrid being html together.
Any pointers would be much appreciated.
Before getting into analyzing and trying to fix this for IE I wondered if James or anyone else have solved similar situations by now.
fist i got heaps of error invoking CFC, internal server error.
checked the cfide folder in IIS and nothing wrong with that , nw i get this new weird error ,
Error invoking CFC /admin/CFC/filter.cfc : Element VALIDATIONHEADER is undefined in ERROR. (no idea what that means)
heres my cfgrid:
<cfgrid format="html" name="employeeGrid" pagesize=50
stripeRows=true stripeRowColor="gray"
bind="cfc:admin.cfc.filter.getfilterIP({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})"
delete="yes" selectmode="edit"
onchange="cfc:admin.cfc.filter.editfilterIP({cfgridaction},{cfgridrow},{cfgridchanged})">
<cfgridcolumn name="filterID" display=true header="filter ID"/>
<cfgridcolumn name="ipAddress" display=true header="IP Address"/>
<cfgridcolumn name="ipFraudRating" display=true header="Fraud Rating"/>
</cfgrid>
the path to the CFC in correct, i'm at my wits end, plz help mate>>>>
error.validationheader
and validationheader is not part of error. You need to check your error logs. This will tell you exactly that file and line this error is being thrown in. It sounds like your error validation code is actually throwing an error itself.
I can confirm this happens in IE with every editable grid I create. Why is this bug not being addressed by Adobe? I tried to post this to the live docs and of course they gonged my post. Any insight or workarounds would be appreciated.
Secondly - be sure you are running the very latest version (8.0.1 with Cumulative Hot Fix)
Edit the data, it disappears, I just tested it.
Can you bind a grid to a URL? If so, do you have some samples that I can refer to?
bind="url:foo.cfm"
You need to add the arguments for cfgrid at the end though.
bind="url:foo.cfm?page={cfgridpage}&pagesize={cfgridpagesize}&sort={cfgridsortcolumn}&sortdir={cfgridsortdirection}">
<a href="http://deepuverma.wordpress.com/2007/08/23/cfgrid-...;
When it is in the CellSelectionModel, it doesn't return the ID (since it now longer selects the row).
Has anyone been able to do CellSelectionModel and still keep BINDs to the grid working?
Thanks!
Chris

ColdFusion.Grid.refresh
not
ColdFusion.Grid.Refresh
:o)
Rob