1

Using CF9 and have a pretty basic html cfgrid that returns results from a SQL query.

There are just two columns in the grid: "ID" and "IDType".

I'm looking to see if there's a way to implement some logic so that when I certain IDType shows up, the value in the ID field becomes the key value in a hyperlink.

Example: IF IDType = "web", and the ID is "1234", the value inside the ID field would show up as http:/www.website.com/1234.html (or...better: just show up as "1234" but be hyperlink-enabled to go to the aforementioned site.)

If the IDType is not (for example) "web", then the value just shows up as a regular cell value (text).

                   <cfgrid
                        name="idGrid"
                        title="Related IDs"
                        query="get_IDs"
                        format="html"
                    >
                        <cfgridcolumn name="ID" header="ID" />
                        <cfgridcolumn name="IDType" header="ID Source" />

                    </cfgrid>
stuttsdc
  • 101
  • 1
  • 4
  • 18

2 Answers2

0

One way to do this is you can generate and append a column to your query using the queryColumnAdd() function, put your link in the cell, and then push the modified query it to the cfgrid.

The link will render and you can click on it!

If I may pseudo code.. first write your normal query

<cfquery name = "myQuery"  datasource = "myCFDatasource">
   SELECT ID, field1, field2, field3
   FROM aTable
</cfquery>

Next, we add your link column onto it..

<cfset queryAddColumn(myQuery, "Link", ArrayNew(1)) />

<cfloop query="myQuery">
    <cfset querySetCell(myQuery, "Link", "http://www.mysite.com/some/index.cfm?ID=#myQuery.ID#"), myQuery.currentRow) />
</cfloop>

Then, you can take your modified query myQuery and submit it into your cfgrid like you did above.

Hope that helps get you on the right path.., worked well for me the last time I used it!

Jas Panesar
  • 6,597
  • 3
  • 36
  • 47
0

You can do it with javascript onRender function.

var gridRender = function()
{
var grid = ColdFusion.Grid.getGridObject('gridname');
var cm = grid.getColumnModel();
cm.setRenderer(0,renderFun); //first arguments stands for column number
}

var renderFun = function(value, cellMeta, record, row, col, data)
{
if(value != null)
{
    switch(col)
    {
        case 0:
            return "<a href='yoururl?id=" & value & "'>" & value & "</a>";      
        default:
            return value;
    }

}
};

And on coldfusion page call gridRender function on ajaxonload

<cfset ajaxOnLoad("gridRender")>

ajaxOnLoad will automatically call gridRender js function on page loaded and setup grid to render through gridRender function. renderFun will call everytime your column cell going to render.

Note: I haven't tested code just consider as test code and modify as per your need.

Pritesh Patel
  • 1,969
  • 1
  • 18
  • 32
  • This looks like a good solution too but I went with the other solution above. I may come back to this one in the future though. – stuttsdc Jul 18 '11 at 18:23
  • That's your choice but it is not advisable to write into query of cfc function either it will not reusable for other purpose. – Pritesh Patel Jul 19 '11 at 04:24