Link a grid row to a url

The CFGrid applet version has a property called href which allows you to link a grid column to a URL. However, this didn't make it into the flash grid for this release (it is high on the enhancement request).

But there is a way, using the onChange attribute of cfgrid and some simple actionscript you can link a selected row to a url.

Thanks to Jared Chandler for this example.

The Actionscript:
-----------------
onchange="getUrl('test.cfm?user_id=' + linkGrid.dataProvider[linkGrid.selectedIndex]['id']);"


Full Example:
------------
<cfif isDefined("url.user_id")>
<cfoutput>
   <p>The selected userid is: #url.user_id#</p>
</cfoutput>
</cfif>

<cfscript>
   myData = queryNew("id,name");
   queryAddRow(myData);
   querySetCell(myData, "id", "a001");
   querySetCell(myData, "name", "John Doe");
   queryAddRow(myData);
   querySetCell(myData, "id", "a002");
   querySetCell(myData, "name", "Jane Doe");
   queryAddRow(myData);
   querySetCell(myData, "id", "b001");
   querySetCell(myData, "name", "Mike Smith");
   queryAddRow(myData);
   querySetCell(myData, "id", "c001");
   querySetCell(myData, "name", "Bob Jones");
</cfscript>

<cfform format="Flash" width="500" height="400">
   <cfgrid name="linkGrid" query="myData"
      onchange="getUrl('test.cfm?user_id=' + linkGrid.dataProvider[linkGrid.selectedIndex]['id']);">

      
      <cfgridColumn name="id" header="userid">
      <cfgridColumn name="name" header="User Name">
      
   </cfgrid>
</cfform>

Comments
john rozier's Gravatar Can this be improved on ? This solution seems to be dependent on using the mouse.
# Posted By john rozier | 3/30/05 11:40 AM
Mike Nimer's Gravatar The keyboard controls are a little odd, but I found that is I tab to the grid, I can use the up/down arrows to select a row. Although it does trigger the onChange for each row you arrow by.
# Posted By Mike Nimer | 3/31/05 10:37 AM
Steve Walker's Gravatar Mike,
I have found an issue and was wondering if this is by design. When I bind a data field (id) that is an integer, it won't work. Switch to a string (varchar) no problem.
# Posted By Steve Walker | 4/12/05 6:28 PM
David Schaller's Gravatar This is great for linking an entire row but how about linking individual row column data. I have data about customer hardware, such as servers and workstations. I have a table that links to the hardware order number details, the server configuration details and provides a direct terminal server link. This would require one row to have three links. Any thoughts?
# Posted By David Schaller | 10/3/05 2:18 PM
diana's Gravatar I've tried your code and it works great when the name for the link is hardcoded, but how do you assigned the link as variable name? For each record there is a different link.


<cfform format="Flash" width="500" height="400">
<cfgrid name="linkGrid" query="reportListing"
onchange="getUrl('#ReportName#.cfr?ReportListingID=' + linkGrid.dataProvider[linkGrid.selectedIndex]['ReportListingID']);">
<cfgridColumn name="ReportListingID" header="ReportListingID" display="no">
<cfgridColumn name="ReportName" header="Report Name">
</cfgrid>
</cfform>
# Posted By diana | 4/18/06 6:12 PM
Mike Nimer's Gravatar That should work just fine. CF Variables are resolved before the cf tags are processed. Make sure you have cfoutput tags around the cfform.
# Posted By Mike Nimer | 4/18/06 10:48 PM
Chaz's Gravatar Hi to all,

I have a question and an answer?

My question is how to display text in a datagrid as ?underline? and only for one or two columns?

This is for David

This is what I use to determine what columns is press?

_global.ListenerCellPress = Object();
_global.ListenerCellPress.cellPress = function(EventObject)
{
var strTileTitle = "";

switch(mydatagrid.getColumnAt(EventObject.columnIndex).columnName)
{
case "ColumnName 1":
your code goes here?
break;
case "ColumnName 2":
your code goes here?
break;
default:
break;
};//End of switch(mydatagrid.getColumnAt(EventObject.columnIndex).columnName)

this will also help with the onChange, because nothing have changed and the function is call only when you press on the column and this is why I need to know how to set the text as underline.
# Posted By Chaz | 5/18/06 12:14 PM
Ben Alembick's Gravatar Any luck with getting a field to be underlined??
# Posted By Ben Alembick | 5/18/07 10:20 AM
Daniel's Gravatar thank' s you Mexico City

excelente articulo...
# Posted By Daniel | 8/28/07 6:24 PM
diana's Gravatar Hi Raymon,

Thank you for sharing your knowledge. I'm currently
using your example, but my link is pointing to an XFDL
file extension. Is there away for CF to recognize this file
extension?
# Posted By diana | 3/19/08 9:31 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.001.