Skip to main content
Known Participant
January 8, 2009
Question

CFGRID, please help

  • January 8, 2009
  • 3 replies
  • 3606 views
I tried to use cfgrip to show the records but I got an error saying Cf can't find the function within my component
I have my component inside a folder called cfcomps, here is the dir structure:
folder www
folder sct
folder cfcomps


What have I done wrong?
Here is my codes and on the most bottom is the error I got:

CODE:
<cfform>
<cfgrid name="ads" format="html" bind="cfc:cfcomps.gcheck.getrecords({cfgridpage}, {cfgridpagesize}, {cfgridsortcolumn}, {cfgridsortdirection})">
<cfgridcolumn name="cp" header="CPrefix" width="100"/>
<cfgridcolumn name="afix" header="APrefix" width="100"/>
<cfgridcolumn name="pid" header="PrefixID" width="300"/>
</cfgrid>
</cfform>


ERROR:

The specified remote function getrecords was not found on the CFC cfcomps.gcheck.

The error occurred in /sp/ourusers/dt/G/checkDt2.cfm: line 58

56 : <cfgridcolumn name="cp" header="CPrefix" width="100"/>
57 : <cfgridcolumn name="afix" header="APrefix" width="100"/>
58 : <cfgridcolumn name="pid" header="PrefixID" width="300"/>
59 : </cfgrid>
60 : </cfform>



This topic has been closed for replies.

3 replies

aleckenAuthor
Known Participant
January 22, 2009
Ken,
Actually what I'm trying to do is very simple.
The select list will show names of tables (sorry I just realized that my naming is wrong. it should be tableName instead of dbname) and when one of the table is selected, the grid will show the content/all columns of that table

So the component has a function where the query is selecting columns from the table selected from the drop down list. That's it.
I will not use any query anymore, this is just to show what are the content of each tables.
Later on I'm learning to add new and update on the grid but for now
I just want to show the content of each table in the grid based on what is selected from the drop down.

As far as the columns of each table to be shown on the grid, they are different, so what I currently have (and is working, except that I don't like the idea of using cfset application.dbname) is using the cfswitch to
navigate to which cfgridcolumn to be used based on the selected table name.(see the logic on the code provided below)

I copy and pasted your example, it is working but only for 1 group of cfgridcolumn. It doesn't make sense to have the selection of table names in the drop down if what is shown on the grid is only a content of one of the table.
Since the beginning I don't know how to connect the selected table name with the cfgrid. This is the reason why I separated the drop down and the cfgrid in 2 CFFORMs

I pasted your example and my cfswitch for you so you can see much clearly what I'm trying to do here.

<CFSWITCH expression="#form.adc#">
<CFCASE value="Bio">
<cfgridcolumn name="FName" header="First Name" width="100"/>
<cfgridcolumn name="LName" header="Last Name" width="120"/>
<cfgridcolumn name="Add" header="Address" width="120"/>
<cfgridcolumn name="City" header="City"width="100"/>
<cfgridcolumn name="State" header="State" width="150"/>
<cfgridcolumn name="Zip" header="Zip Code" width="300"/>
</CFCASE>
<CFCASE value="Dept">
<cfgridcolumn name="HR" header="Human Resources" width="100"/>
<cfgridcolumn name="IT" header="Information Technology" width="120"/>
<cfgridcolumn name="Add" header="Admission" width="120"/>
<cfgridcolumn name="Reg" header="Registration" width="150"/>
<cfgridcolumn name="Fin" header="Financial Aids" width="100"/>
</CFCASE>
</CFSWITCH>




Inspiring
January 25, 2009
This will require a page reload so that the grid can be re-defined with each selection from the select list.

So, I would have a cfparam to store the initial value of the select list (this could also be used in the select list to select the option. Then in the call to the cfc in the bind just use the form value.

See attached code


Ken
aleckenAuthor
Known Participant
January 21, 2009
Ken,
The CFSELECT is on the same page with the CFGRID and No I don't have "please select" option on my cfselect.
My CFComponent is on a different page (cfc page)
I did <cfset application.dbname="#form.adc#">
because it seems the dbname was not passed to the component
I've been debuging for awhile and still can't understand what is the problem. that's why I tested by setting the dbname to an application scope (may be I can also set it up to session or client scope)

Here are my codes on the cfselect, cfgrid and cfc:
(Thanks for looking Ken)

<form method="post" action="checkdata.cfm?cfdebug=1">

<tr>
<td width="25%">Select from the list</td>
<td>
<select name="adc">
<cfoutput query="adclist">
<option value="#DBName#" <cfif IsDefined("form.adc")><cfif #MID# EQ #Form.adc#>selected</cfif></cfif>>#MName#
</cfoutput>
</select>
<input type="submit" value="GO">
</td>
</tr>
<tr><td colspan="2"> </td></tr>
<tr><td colspan="2">
</form>

<cfif IsDefined("form.adc")>

<!--- Currently I put this one down to make it work --->
<cfset application.dbname="#form.adc#">
<!--- end of my testing --->


<cfform name="adcform">
<cfgrid name="advcodesgrid" format="html" pagesize="10"
striperows="yes"
selectmode="row"
bind="cfc:test.cfcomps.gcheck.adc_check({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection},' { adc } )" sort="true">
cfgridcolumn name="CamPr" header="CPrefix" width="100"/>
<cfgridcolumn name="ADCPref" header="ADC CODE" width="100"/>
<cfgridcolumn name="PrefID" header="Prefix ID" width="300"/>
</cfgrid>
</cfform>
</cfif>

<cfcomponent displayname="gr_adc">

<cffunction name="adc_check" access="remote" returntype="struct">

<!--- MUST DECLARE THESE ARGUMENTS! --->
<cfargument name="cfgridpage" type="numeric" required="true" />
<cfargument name="cfgridpageSize" type="numeric" required="true" />
<cfargument name="cfgridsortcolumn" type="string" required="no" default="" />
<cfargument name="cfgridsortdirection" type="string" required="no" default="" />
<cfargument name="dbname" type="string" required="yes">

<!--- Local variables --->
<cfset var results="">

<cfquery name="getInfo" datasource="ADC">
select * from #application.dbname#
</cfquery>

<!--- And return it as a grid structure --->
<cfreturn queryConvertForGrid(getinfo, cfgridpage, cfgridpageSize)>


</cffunction>

</cfcomponent>







Inspiring
January 21, 2009
I don't think you really want to filter the grid here !!
A filter is where a grid is loaded and then a column (lets say city) is filtered by the selected option.
If I understand your code you want to do the following

The user selects an option from the select list
The selected option is then used in the query as the table to query.

Do all the tables in the select list havve the same column names ?

If not this will cause a problem when trying to load the grid.
I think as you have the select list in different form from the grid you need to preceed the name with the form name (not sure on this)

Also there is no need for the submit button, this is what the bind is for.
So, assuming the tables have the same column names, the following sould work.
All you will need to do is select a different option in the select list, see attached code.
Copy to a page as is and it should work.

Also for future reference a pointer

Instead of your code
<option value="#DBName#" <cfif IsDefined("form.adc")><cfif #MID# EQ #Form.adc#>selected</cfif></cfif>>#MName#

Try
<cfparam name="form.adc" default = "">
Then in the select <option value="#DBName#" <cfif #MID# EQ #Form.adc#>selected</cfif>#MName#

I don't know where MID comes from but it should be DBName

Ken
Inspiring
January 8, 2009
If the cfc is not in the same directory as the calling page, then you have to specify the complete path to the cfc from the web root
So, in your case you need to add the "sct" directory to the path

bind="cfc:sct.cfcomps.gcheck.getrecords

Ken
aleckenAuthor
Known Participant
January 9, 2009
OK that's my fault and I have added the right path and the error doesn't show up but unfortunately another error showed up and it says:
The PAGESIZE argument passed to the getrecords function is not of type numeric.

I've googled this error and did not get any helpful result. This is the first time I'm using cfgrid in CF8, honestly my knowledge on this is as much as what is available out there on the net.
To my understanding, I need to include these arguments to my function within my component to make cfgrid work, So I added them there otherwise I got a different error message.

<cfargument name="page" type="numeric" required="false">
<cfargument name="pagesize" type="numeric" required="true">
<cfargument name="sortcol" type="string" required="false">
<cfargument name="sortdir" type="string" required="false">
<cfargument name="filter" type="string" required="false">
but after adding these arguments, I got The PAGESIZE argument passed to the getrecords function is not of type numeric.

Here is my codes again:
Here is how I invoke my component:
<cfinvoke component="sct.cfcomps.gcheck" method="getrecords" dbname="#form.adc#" returnvariable="q_adc">

Here is my component:
<cfcomponent>

<cffunction name="getrecords" access="remote">
<cfargument name="dbname" required="true">
<!--- MUST DECLARE THESE ARGUMENTS! --->
<cfargument name="page" type="numeric" required="false">
<cfargument name="pagesize" type="numeric" required="true">
<cfargument name="sortcol" type="string" required="false">
<cfargument name="sortdir" type="string" required="false">
<cfargument name="filter" type="string" required="false">

<cfquery name="getcodes" datasource="adc">
select * from #dbame#
</cfquery>

<cfreturn getcodes/>

</cffunction>

</cfcomponent>







aleckenAuthor
Known Participant
January 9, 2009
Ok I have searched so many sites for this error and none shed a light as to why I still get this error.
I changed my codes to follow one of Ben Forta's posting about cfgrid and still get the same error.
I also found a posting suggesting that there may be a missing CF8 dictionary with possibility of throwing a syntax error, i search for cf8.xml under cfeclipse plugin & dictionary folder and found that the pagesize is listed with a default value=10, so what causes the error which says that the pagesize in not numeric and the value is empty???
At the bottom is the section from CF8.xml from the ditionary where pagesize should has value by default.

and here is the error from Coldfusion AJAX Logger:
error:http: Error invoking CFC /sct/cfcomps/gcheck.cfc : The PAGESIZE argument passed to the advcode_check function is not of type numeric.

info:widget: Creating window: cf_window1231525570699

info:widget: Created grid, id: adcgrid

info:http: HTTP GET /sct/cfcompos/gcheck.cfc?method=getrecordsk&returnFormat=json&argumentCollection=%7B%22dbname%22%3A1%2C%22page%22%3A7%2C%22pageSize%22%3A%22%22%2C%22gridsortcolumn%22%3A%22%22%2C%22gridsortdir%22%3A%22gl_prefixes%22%7D&_cf_nodebug=true&_cf_nocache=true&_cf_clientid=C23A32FF81E3004BC0157C2B9D086899&_cf_rc=0

info:http: Invoking CFC: /sct/cfcomps/gcheck.cfc , function: getrecords , arguments: {"dbname":1,"page":7, "pageSize":"" ,"gridsortcolumn":"","gridsortdir":"gl_prefixes"}

info:LogReader: LogReader initialized

info:global: Logger initialized

Please help