froadie
froadie

Reputation: 83153

Can I replace the cfgridkey with my own custom variable name? Or else build my own href?

I have a simple cfgrid that's displaying my ids. I want the id to be a link to a new page, passing a url parameter of "myID" with the id value.

I've tried this code:

<cfgrid name="myGrid" query="myQuery" format="html">
   <cfgridcolumn name="myID" href="mynewpage.cfm" />
</cfgrid>

But this takes me to the url "mynewpage.cfm?hrefkey=111". What I really want is "mynewpage.cfm?myID=111". Is there any way to specify what the name of the url parameter should be?

I've also tried:

<cfgrid name="myGrid" query="myQuery" format="html">
   <cfgridcolumn name="myID" href="mynewpage.cfm?myID=#myID#" />
</cfgrid>

But then I get the error "myID is not defined". Is there any way to reference query field values from within a cfgridcolumn tag?

UPDATE:

Another thing I've tried - building the string in the sql query so that I return a column called myURL with a value of "mynewpage.cfm?myID=111", and then using that column for the href attribute:

<cfgrid name="myGrid" query="myQuery" format="html">
   <cfgridcolumn name="myID" href="#myURL#" />
</cfgrid>

According to the coldfusion documentation you should be able to do this:

href - URL or query column name that contains a URL to hyperlink each grid column with.

(italics mine)

But I get the error "myURL is not defined". How do I set the href to a column rather than a literal url value?

Upvotes: 4

Views: 561

Answers (2)

Suman
Suman

Reputation: 1

One solution is in this page:

http://www.houseoffusion.com/cfdocs1/Developing_Web_Applications_with_ColdFusion/14_Building_Dynamic_Forms/dwa14_09.htm

Define a new column using

<cfset queryAddColumn(SPEREQ_QRY_UNFULFILLED, "CUST_LINK", ArrayNew(1)) />

<cfloop query="SPEREQ_QRY_UNFULFILLED">
  <cfset querySetCell(SPEREQ_QRY_UNFULFILLED, "CUST_LINK","index.cfm?action=contact_info&cust_id=#SPEREQ_QRY_UNFULFILLED.CUST_CNTCT_LMS_ID#", SPEREQ_QRY_UNFULFILLED.currentRow) />
</cfloop>

use this new column cust_link in the display

<cfgridcolumn name = "CUST_CNTCT_LMS_ID" header="CustID"  
     href="CUST_LINK" target="_blank" width="20">
<CFGRIDCOLUMN NAME="CUST_LINK" DISPLAY="No">

Upvotes: 0

Alex
Alex

Reputation: 7833

This is similar to the <cftree>/<cftreeitem> problem using href. There does not seem to be a built-in solution for this. Either you deal with the provided keys and rename the whole address using outbound URL rewrite (IIS has native support, Apache can do this with UrlRewriteFilter), or you might just switch to a different Javascript based grid.

Upvotes: 1

Related Questions