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

CFGRID, please help

Community Beginner ,
Jan 08, 2009 Jan 08, 2009
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>



TOPICS
Getting started
3.3K
Translate
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
Enthusiast ,
Jan 08, 2009 Jan 08, 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
Translate
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 Beginner ,
Jan 09, 2009 Jan 09, 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>







Translate
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 Beginner ,
Jan 09, 2009 Jan 09, 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
Translate
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
Enthusiast ,
Jan 10, 2009 Jan 10, 2009
I'm a bit confused with where you are at now.
Originally you had the bind attribute in the cf grid, but in the last post you are using cfinvoke.

You need to bind the cfc to the cfgrid.

Go to the online docs, best place for info
Online Docs CFGrid

The find the link "Using HTML format grids" there are great examples to show you how to use it.

Ensure that your grid follows the example and that you cfc also follows the example.

Ken
Translate
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 Beginner ,
Jan 14, 2009 Jan 14, 2009
ken, what I still don't understand with bind is, once it calls the function then the function will run my sql
the function then will return a recordset to the calling page where bind is located.
Where is this recordset used?

If I do a static cfgrid, I did not use bind but in the cfgrid there is a query attribute. And cfgrid will use this recordset to show those records.
But with bind I don't see where can I use the recordset returned to create a grid.
I did use <cfreturn QueryConvertForGrid on my function to return the value in the form of a structure to the caller page but where is the variable that this structure supposed to be assigned to?
Translate
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 Beginner ,
Jan 14, 2009 Jan 14, 2009
OK, after hours and hours of debuging and googling I found out that the error was not due to anything but passing an extra variable in the bind attribute.
It looks like many people experiencing the same error as I do but unfortunately I have not found the answer yet.

When I removed that extra parameter I'm supposed to pass to my cfc, I got a nice grid result with no error.
So this code is working BUT I can't use it in my application since I need to pass a parameter to my CFC:

<cfgrid name="adcgrid"
format="html"
pagesize="10"
striperows="yes"
selectmode="row"
bind="cfc:test.cfcomps.gcheck.adccheck({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})" sort="true">
etc...
</cfgrid>

This code DOESN'T WORK since I added an extra parameter to be passed to my CFC:
The error is saying that my pagesize is non numeric!!

<cfgrid name="adcgrid"
format="html"
pagesize="10"
striperows="yes"
selectmode="row"
bind="cfc:test.cfcomps.gcheck.adccheck({cfgridpage},{cfgridpagesize},{cfgridsortcolumn}, {cfgridsortdirection}, '#dbname#' )" sort="true">
etc...
</cfgrid>

Does anyone know a way to pass parameter to cfc via bind attribute of CFGRID?
Translate
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
Enthusiast ,
Jan 14, 2009 Jan 14, 2009
Where is the dbname value coming from ?
Do you have a function argument in the cfc for this value ?
What is the error you are getting with this ?


Edit:
The normal thing is to pass a javascript value. As this will be the only way you could get the user to interact with the grid.
Ken
Translate
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 Beginner ,
Jan 15, 2009 Jan 15, 2009
Here is my codes:
This is checkdata.cfm
<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>

<!--- form submitted to the same template, checkdata.cfm --->
<cfif IsDefined("form.adc")>

<cfwindow initshow="true" center="true" width="630" height="340" title="#form.advcode#">

<cfform name="adcform">
<cfset dbname="#form.advc#">

<!--- the back-end cfc has a single method adc_check --->
<cfgrid name="adcgrid"
format="html"
pagesize="10"
striperows="yes"
selectmode="row"
bind="cfc:test.cfcomps.gcheck.adc_check({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection},' #dbname# ')" 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>

</cfwindow>

</cfif>

<!--- Here is the component & function --->
<cfcomponent displayname="gr_adc">

<cffunction name="adc_check" access="remote" returntype="struct">
<cfargument name="dbname" type="string" required="yes">
<!--- 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="" />

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

<cfquery name="getrecords" datasource="ADC">
select * from #arguments.dbname#
</cfquery>

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


</cffunction>

</cfcomponent>

<!--- Here is the error --->
error:http: Error invoking CFC /test/cfcomps/gheck.cfc : The CFGRIDPAGESIZE argument passed to the advcode_check function is not of type numeric.

On my testing:
If I get rid of the parameter #dbname# from bind attribute than hard coded the dbname on the function
the cfgrid work
Translate
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
Enthusiast ,
Jan 15, 2009 Jan 15, 2009
First thing is the order of the params

In the grid you have
({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection},' #dbname# ')

But in the cfc you have
<cfargument name="dbname" type="string" required="yes">
<!--- 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="" />


These need to be in the same order.

Now to make it easier for you change the form to a cfform and the fields to cf fields.

Then just reference the cfselect name in the bind, like so
({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection}, {adclist})

Here is a tutorial to help you understand

Ken
Translate
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 Beginner ,
Jan 16, 2009 Jan 16, 2009
Ken, I followed your suggestion and it got rid of the previous error I had, about the pagesize is non numeric etc.
With your suggestion I did not get that error message but I got an empty grid
When I looked at the debug screen (using the ?debug=1) I saw the dbname: NULL and an error message about
bind element is not found.

This may caused by the paramater passed via the bind attribute where you put adclist which is the name of the query populating cfselect instead of the name of cfselect. I changed that to the name of the cfselect which is adc and I still get the grid with no records.
Since I did not get any error, than dbname variable must have been passed to the function but for some reason the value did not get passed(?) so I got around it by setting the dbname variable into an application scope as follow:

<!--- form submitted to the same template, checkdata.cfm --->
<cfif IsDefined("form.adc")>

<cfform name="adcform">

<!--- I did this --->
<cfset application.dbname="#form.adc#">

<!--- instead of this --->
<cfset dbname="#form.adc#">

<!--- the back-end cfc has a single method adc_check --->
<cfgrid name="adcgrid" 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>

</cfwindow>

</cfif>

and on the function I have the following:

<!--- 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">

Now it is working, it shows the grid with a proper records everytime I select the dbname from the drop down and no error message anywhere.
But I'm not sure if setting dbname variable into an application scope is a good idea?
Translate
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
Enthusiast ,
Jan 16, 2009 Jan 16, 2009
I don't think you should be setting either of the dbname variables you listed.

The cfselect is in the same page as the grid is it not ?

One thing to check is that the cfselect has a valid selected option when the page loads.
That is do you have a "please select" option ?

If so this will pass an empty value to the cfc, you just need to check the value in the cfc and not include it in the query if it is empty.

Without seeing the code for the cfselect, cfgrid and the cfc I can;t really say.

Ken
Translate
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
Enthusiast ,
Jan 14, 2009 Jan 14, 2009
Using the query attribute will populate the grid with the entire record set.
You will also need to do a page reload to pass a new paramater value to the cfc.
Also note that the cfgrid paging params have no effect (as far as I know)

Using the bind attribute will give you paging automatically (by passing the cfgrin paging params)
It will also allow you to pass a paramater (eg a filter) to apply to the cfc without the need for a page reload.

Ken
Translate
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 Beginner ,
Jan 21, 2009 Jan 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>







Translate
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
Enthusiast ,
Jan 21, 2009 Jan 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
Translate
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 Beginner ,
Jan 22, 2009 Jan 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>




Translate
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
Enthusiast ,
Jan 24, 2009 Jan 24, 2009
LATEST
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
Translate
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