Skip to main content
June 3, 2009
Question

getting the parameters in url using cfgrid to cfc....

  • June 3, 2009
  • 1 reply
  • 1400 views

please help!!!

passing parameters to cfc using the cfgrid bind...

im using the cfc bind if u hard coded the query in the cfc its works but if u need to pass a parameters in cfc bind its not working...

for example...

my url with parameter is http://localhost/index.cfm?empid=123&start_date=2009/05/01

<cfform>       
            <cfajaxproxy bind="javascript:todetail({maingrid.id@change},{maingrid.firstname@none},{maing rid.lastname@none})" />
            <cfgrid format="html"
                name="maingrid"
                bind="cfc:#request.cfcpath#users.getGridas({cfgridpage},{cfgridpagesize},{cfgri dsortcolumn},{cfgridsortdirection})"
                preservepageonsort="true"
                appendkey="no"           
                selectonload="false"
                width="750"                           
                style="clear:both;" colheaderalign="center"
                >
               
                <cfgridcolumn name="id" display="no" />
                <cfgridcolumn name="datatime" header="DATE" width="100"/>               
            </cfgrid>
        </cfform>

my query in cfc file:

select * from hrd_emp

WHERE 0=0
            <cfif arguments.id NEQ "">AND (id='#arguments.id#')</cfif>
            <cfif arguments.whereClause NEQ "">AND (#preserveSingleQuotes(arguments.whereClause)#)</cfif>
           
            AND (EmpNo = '#######')   =====> i need to put the empid=123 from the url  http://localhost/index.cfm?empid=123&start_date=2009/05/01

PLEASE HELP!!!

    This topic has been closed for replies.

    1 reply

    Inspiring
    June 3, 2009

    Pam, here's how I solved this one. Note the order of the bindings and the order of the bindings in the CFC must be the same as well. Hopefully this helps:

    <!--- create cfgrid with results from url.CFGRIDKEY variable --->
    <cfform name="getUsers">
           <cfgrid format="html" name="displayUsersActive" autowidth="yes" selectmode="row" striperows="yes" pagesize="13" bind="cfc:getUsers.SPActiveUsers({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection},'#url.CFGRIDKEY#')" width="700" height="360">
                <cfgridcolumn name="intfkclassid" display="no">
                <cfgridcolumn name="txtLName" header="Last Name" headerbold="yes" width="20">
                <cfgridcolumn name="txtFName" header="First Name" headerbold="yes">
                <cfgridcolumn name="startdate" header="Start Date" width="30" headerbold="yes">
                <cfgridcolumn name="enddate" header="End Date" headerbold="yes">
                <cfgridcolumn name="classno" header="Class No" headerbold="yes" hrefkey="intfkclassid" href="allEnrolled.cfm" >
            </cfgrid>
        </cfform>

    <!--- getUsers.cfc ----------->

    <cfcomponent>
        <!--- METHOD: List Active users method --->
        <CFFUNCTION NAME="SPActiveUsers" access="remote" RETURNTYPE="struct">
            <cfargument name="gridpage" type="numeric" required="true" />
            <cfargument name="gridpagesize" type="numeric" required="true" />
            <cfargument name="gridsortcolumn" type="string" required="true" />
            <cfargument name="gridsortdirection" type="string" required="true" />
            <cfargument name="cfgridkey" required="false" type="string" default=""/>

         <cfif arguments.gridsortcolumn eq "">
                <cfset arguments.gridsortcolumn = "txtLName" />
                <cfset arguments.gridsortdirection = "asc" />
            </cfif>
               
             <!--- get user's info --->
                 <cfquery datasource="#application.dsn#" name="getUsers">
                        select a.intuserid,
                                a.txtFname,
                                a.txtLname,
                                b.intfkclassid,
                                c.intclassid,
                                convert(varchar,c.dtstartdate,106) as startdate,
                                convert(varchar,c.dtenddate,106) as enddate,
                                right('00' + convert(varchar,c.intclassyr),2) + '-' + right('00' + convert(varchar,c.intclassno),2) as classno,
                                c.intclassNo,
                                c.intclassyr
                        from tblusers a, tblenrollment b, tblclasses c
                        where a.intuserid = b.intfkuserid and
                                b.intfkclassid = c.intclassid
                                <cfif arguments.cfgridkey NEQ "" and isnumeric(arguments.cfgridkey)>
            and c.intclassid = #arguments.cfgridkey#
                                <cfelseif arguments.cfgridkey NEQ "" and arguments.cfgridkey EQ "active">
                                and c.blnIsActive = 1
                                <cfelseif arguments.cfgridkey NEQ "" and arguments.cfgridkey EQ "inactive">
                                and c.blnIsActive = 0
                                <cfelse>
                                and 1 = 1
                                </cfif>
                        order by #arguments.gridsortcolumn# #arguments.gridsortdirection#
                        </cfquery>
               
              <CFRETURN queryconvertforgrid(getUsers, gridpage, gridpagesize)>
        </CFFUNCTION>
    </cfcomponent>

    June 3, 2009

    thanks welker...

    sorry for being stupid lmao... ive got an error...

    Element CFGRIDKEY is undefined in URL.

    i add the...

    <cfif isDefined('url.cfgridkey')>
    <cfset url.empid = url.CFGRIDKEY>
    <cfelse>
    </cfif>

    then

    from my cfgrid

    <cfgrid format="html"
                    name="maingrid"
                    bind="cfc:#request.cfcpath#users.getGridas({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection},'#url.CFGRIDKEY#')"
                    preservepageonsort="true"
                    appendkey="no"           
                    selectonload="false"
                    width="750"                           
                    style="clear:both;" colheaderalign="center" striperows="yes"
                    >

    pls help... thanks!

    Inspiring
    June 3, 2009

    i used a default setting for the cfgridkey like this:

    <!--- set default para for GRIDKEY when not defined --->
    <cfparam name="url.CFGRIDKEY" default="all">

    so you can use your statement but set an else value or a cfparam

    see how that works.