Skip to main content
Participant
October 16, 2010
Question

How to pass an URL with cfgrid (forget my other post with cfgridrow)

  • October 16, 2010
  • 2 replies
  • 1055 views

Basically I am using cfgrid to display a list of computer from a query.  I would lke to be able to; when I click on the first colum in any row to display a cfm page that will be able to display relevant information to a specific computer.  I will be passing parameter with theurl parameter.  Theses parameter are generated by my original query.

here is the code i am trying to use.  I didn't include the href.

This code works OK.  The 2 variables I am trying to send via URL are #machine# which is created from a query and URL.Hotel which is was send thru the URL when I opened this page. (the cfoutput tag were remove )
<!---<table border="1"
  <TR>
    <TD> PC Name </TD>
    <TD> IP Address </TD>
    <TD> User Name </TD>
  </TR>
  <cfoutput query="listRet">
  <tr>
    <td><a href="ListApp.cfm?pc=#URLEncodedFormat(Trim(Machine))#&hotel=#URL.hot el#">#Machine#</a></td>
    <td>#IPAddress#</td>
    <td>#Description#</td>
  </tr>
  </cfoutput>
</table>--->

Now can I do the same with a cfgrid and cfgrid row

<cfform format="flash">
<cfgrid
  query="listRet"
  name="gridPc"
  height="400"
  width="1000">
  <cfgridcolumn name="Machine" header="PC Name" headerbold="true" headertextcolor="blue" width="120">
  <cfgridcolumn name="Description" header="User Name" headerbold="true" headertextcolor="blue" width="250">
  <cfgridcolumn name="IPAddress" header="IP Address" headerbold="true" headertextcolor="blue" width="120">
  <cfgridcolumn name="SystemName" header="Model" headerbold="true" headertextcolor="blue" width="275">
</cfgrid>
</cfform>

Thanks

    This topic has been closed for replies.

    2 replies

    Participating Frequently
    October 29, 2010

    For those of you that want to use cfgrid and pass a complex string of URL parameters to use with hrefkey.

    In this example I am quering a department table in Oracle.  I found that if you contruct your URL parameters in the SQL you can typically accomplish the goal of passing a complex URL string.

    See the cfquery in the component below:

    <!----report.cfc--->

    <cfcomponent>
        <cffunction name="getDepartment" access="remote" returntype="any">
        <cfargument name="page" type="numeric" required="yes">
        <cfargument name="pageSize" type="numeric" required="yes">
        <cfargument name="gridsortcolumn" type="string" required="no" default="">
        <cfargument name="gridsortdirection" type="string" required="no" default="">
        <cfset rsData = "">
       
        <cfif ARGUMENTS.gridsortcolumn EQ "">
        <cfset ARGUMENTS.gridsortcolumn = "DEPTNO" />
        <cfset ARGUMENTS.gridsortdirection = "ASC" />
        </cfif>
       
        <!---Queries to be found in I:\Dashboard.--->
        <cfquery name="rsData" datasource="#dsn#">
        SELECT deptName, deptNo ,
       <!---Create URL String in SQL (Oracle Example).--->
        TO_CHAR('&deptNo=' || deptNo || '&deptName=' || deptName) AS hrefKey
       <1---End.--->
        FROM swweb.tbl_department
        <cfif ARGUMENTS.gridsortcolumn NEQ "" OR ARGUMENTS.gridsortdirection NEQ "">
        ORDER BY #ARGUMENTS.gridsortcolumn# #ARGUMENTS.gridsortdirection#
        </cfif>
        </cfquery>
        <cfif ARGUMENTS.export EQ "">
        <cfif rsData.RecordCount NEQ 0>
        <cfreturn QueryConvertForGrid(rsData, ARGUMENTS.page, ARGUMENTS.pageSize)>
        <cfelse>
        <cfreturn QueryConvertForGrid(rsData, 0, 0)>
        </cfif>
        <cfelse>
        <cfreturn rsData>
        </cfif>
        </cffunction>
    </cfcomponent>

    <!---test.cfm--->

    <cfparam name="URL.deptNo" default="0">
    <cfparam name="URL.deptName" default="None">
    <cfparam name="FORM.pageDept" default="1">
    <cfparam name="FORM.pageSizeDept" default="7">
    <cfset VAR.gridWidth = 800>
    <cfset VAR.gridcolBGColor = '##CCCCCC'>
    <cfoutput>#URL.deptNo# - #URL.deptName#</cfoutput><br /><br />

    <div id="reportTitle">Departments</div>
    <div id="reportContainer">
    <cfform>
    <cfgrid name="sales_dept_vs_prior" format="html" pagesize="#FORM.pageSizeDept#" width="#VAR.gridWidth#" bind="cfc:cfc.report.getDepartment({cfgridpage}, {cfgridpagesize}, {cfgridsortcolumn}, {cfgridsortdirection})" striperows="yes" selectonload="false" bindonload="yes">
        <!---Must include hrefKey column like this.--->
        <cfgridcolumn name="hrefKey" display="no">
        <!---Add href & hrefKey below.--->
        <cfgridcolumn name="DEPTNO" header="Dept. No" width="50" href="#CGI.SCRIPT_NAME#?taskID=HELLOWORLD" hrefkey="hrefKey">
        <cfgridcolumn name="DEPTNAME" header="Name" width="70" bgcolor="#VAR.gridcolBGColor#">
        </cfgrid>
    </cfform>
    </div>

    Inspiring
    October 16, 2010

    The documentation on cfgridcolumn tells you how to put anchor tags and url variables into a grid.