• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

cfgrid and href attribute issue

Engaged ,
Oct 21, 2009 Oct 21, 2009

Copy link to clipboard

Copied

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

TOPICS
Advanced techniques

Views

3.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 30, 2009 Oct 30, 2009

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 01, 2009 Nov 01, 2009

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 01, 2009 Nov 01, 2009

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 01, 2009 Nov 01, 2009

Copy link to clipboard

Copied

First, it involves extra work on the server side.

So? Fetching and manipulating data is the job of the server, not the client.  The client should simply be displaying what it's told to display, and how it's told to display it.

Second, it mixes presentation code(grid) with business code(query).

No it doesn't.  No more than having any other sort of URL in there.  Indeed your option is pushing business logic onto the client, in that it's down to client-side view code to build the URLs, which is definitely not the job of view code.

Anyway, doing it via the mechanism that CF actually provides to achieve the end is a much better approach that buggering about with client-side JS to hack something that one could instead do out-of-the-box.

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.

It's definitely less than ideal that there is no way to suppress that column from outputting in the grid.  That is dumb.  However the HREF is appied to ALL the cells of the grid, not just the one displaying the HREF.  Anyway, that's easily solved by using <cfgridcolumn> tags to specify which columns to display.  And indeed then one can specify different URLs for each column that way, should one wish to.

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 01, 2009 Nov 01, 2009

Copy link to clipboard

Copied

...FWIW, I'm using ModelGlue (2.0) and I call the cfgrid code in question in a view but reference the query from a call in the controller via code instantiated from the model. This debate has arisen in the ModelGlue Google group and is quite entertaining; I think the end result was that folks agreed to disagree and there was no concrete, undisputed right or wrong way to do it. Like a lot of the rest of the ColdFusion platform, they're are usually more than several ways to accomplish a task and this way seemed to work best for me.

But Adobe could make an enhancement or two with the cfgrid tags and make it even easier....

Thanks to all for your help and suggestions,


Rich

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 02, 2009 Nov 02, 2009

Copy link to clipboard

Copied

LATEST
Adobe could make an enhancement or two with the cfgrid tags and make it even easier...

I am sure it will happen. In fact, it already has in a way!

Coldfusion now includes the ext library. The solution to your problem is there somewhere. I bet it is more trivial than what we've been doing here, if only you know how.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 02, 2009 Nov 02, 2009

Copy link to clipboard

Copied

Indeed your option is pushing business logic onto the client

With Javascript presentation and onclick code?

it's down to client-side view code to build the URLs, which is definitely not the job of view code.

You lost me there. Isn't the browser, that is, the client, part of the View?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 01, 2009 Nov 01, 2009

Copy link to clipboard

Copied

Thanks everyone for your input. I actually went with something along the lines that Adam described, even though  it is not exactly as free and autonomous of a solution that I would like it still permitted enough of a dynamic workflow to handle my use case.

When the smoke clears from my deadline I'll be submitting to Adobe for a feature request, otherwise this CFGRID is a very useful tool for the CFML library.

Many thanks,

Rich

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 01, 2009 Nov 01, 2009

Copy link to clipboard

Copied

When the smoke clears from my deadline I'll be submitting to Adobe for a feature request

Indeed. I do believe it would be a straightforward addition, given that Coldfusion now has the ext library!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 01, 2009 Nov 01, 2009

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation