Skip to main content
Inspiring
October 22, 2009
Question

cfgrid and href attribute issue

  • October 22, 2009
  • 2 replies
  • 3290 views

HI Gang-

I'm building a relatively simple query driven cfgrid, read-only for the most part but I need one of the columns to be a href value that will serve as a drilldown. Everything working fine except that the name/value pair I need appended to the url is being persnickety.

The url I'd like to build and have effected in the cfgrid is something like "index.cfm?action=drilldown&orderid=#dynamicValue#"

I finally got it to work, but not as I would like. Turns out both cfgrid and cfgridcolumn tags each have the "href" and the "hrefkey" attributes, which made for a confusing 45 minutes of trial and error.  The closest I could eventually come to my target url of:

index.cfm?action=drilldown&orderid=#dynamicValue#

is actually

index.cfm?action=drilldown&CFGRIDKEY=#dynamicValue#

Not what I wanted but I can deal for now.

Has anyone gotten a hold of building out hrefs in cfgrid using custom name/value pairs dynamically? Would love to know how you did it. Code postings would be even better!

Many thanks,

Rich

This topic has been closed for replies.

2 replies

BKBK
Community Expert
Community Expert
November 1, 2009

Quite a challenge, that one. You can run the following example directly. Have a look at my use of the lastName column. You could also have a look at the ext library.


<html> 
<head> 
     <title>Grid URL Demo</title> 
     <script type="text/javascript"> 
     function init(){ 
         var grid = ColdFusion.Grid.getGridObject("ArtistGrid"); 
         grid.addListener("rowclick",onRowClick); 
     } 
     
     function onRowClick(g,rowIndex,e){
       var lastName = ColdFusion.getElementValue("ArtistGrid", "artistGridForm", "lastName");
       var url = "index.cfm?action=drilldown&lastName="+lastName;
       ColdFusion.navigate(url);    
     }
     
     </script>     
</head> 
<body> 
      
     <cfquery name="getArtists" datasource="cfartgallery"> 
     SELECT artistId, firstname, lastname, address, city, state, postalcode, email 
     FROM Artists 
     </cfquery> 
      
     <cfset args = structNew()> 
     <cfset args.name = "ArtistGrid"> 
     <cfset args.format = "html"> 
     <cfset args.query = "getArtists"> 
     <cfset args.stripeRows = true> 
     <cfset args.selectColor = "##D9E8FB"> 
     <cfset args.width = 600> 
          
     <h1>Artists Grid</h1>       
     <cfform name="artistGridForm" id="artistGridForm"> 
        <cfgrid attributeCollection="#args#"> 
           <cfgridcolumn name="artistid" display="false"> 
           <cfgridcolumn name="firstname" header="First Name"> 
           <cfgridcolumn name="lastname" header="Last Name"> 
           <cfgridcolumn name="email" header="Email Address"> 
           <cfgridcolumn name="address" header="Address"> 
           <cfgridcolumn name="city" header="City"> 
           <cfgridcolumn name="state" header="State"> 
           <cfgridcolumn name="postalcode" header="Zip"> 
        </cfgrid> 
     </cfform>  
     <cfset ajaxOnLoad("init")>      
</body> 
</html>

Inspiring
October 31, 2009

I think the CFGRIDKEY approach as documented is as good as it gets currently.  I googled about the place for a solution, and the "best" I found was this blog entry - http://www.danvega.org/blog/index.cfm/2008/3/21/ColdFusion-9-WishList-Calling-for-suggestions - in which someone requests more flexibility as per your requirement.

There does not seem to be an E/R for it in the CF bug base (http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbugtracker/main.html#), so perhaps you might like to raise one?  I'll vote for it too if you feed-back what the E/R number is.

--

Adam

Inspiring
November 1, 2009

Actually, now that I have engaged my brain, this is quite easy.

Add a column to your query that has your href in it, and then use the HREF attribute to use that for the HREF of the grid cells.

EG:

<!--- Query the database to fill up the grid. --->
<cfquery name = "qCourses" dataSource = "cfdocexamples">
    SELECT        Course_ID, Dept_ID, CorNumber, CorName, CorLevel
    FROM        CourseList
    ORDER by    Dept_ID ASC, CorNumber ASC
</cfquery>

<cfquery name="qCourses" dbtype="query">
    select    *, '#CGI.script_name#?course_id=' || cast(Course_ID as varchar) || '&Dept_ID=' || cast(Dept_ID as varchar) as courseHref
    from    qCourses
</cfquery>

Obviously this example is just reusing column data from the query, but the courseHref column could contain anything.

--

Adam

BKBK
Community Expert
Community Expert
November 1, 2009

Actually, now that I have engaged my brain, this is quite easy.

Add a column to your query that has your href in it, and then use the HREF attribute to use that for the HREF of the grid cells.

In my opinion, this doesn't quite face the challenge head-on. For at least 3 reasons. First, it involves extra work on the server side. Second, it mixes presentation code(grid) with business code(query). Third, and most important, it is actually a static, not a dynamic, solution. The user clicks on a predetermined list of URLs and not, for example, on the course_id column as is required.