Copy link to clipboard
Copied
HI, I am trying to learn how to create an editable datagrid. I have built a .cfc with a getdata function that displays data in the grid. When I add an update function and preview the girid page, I get an error saying it now cannot find the cfc. This is little harder than I thought. Can anyone help or know of a tutorial they might save me a few hours--- thank you - jim
The specified CFC forms3 could not be found. | |
The path to the CFC must be specified as a full path, or as a relative path from the current template, without the use of mappings. |
CODE For .cfc
<!---DISPLAY DATA IN GRID--->
<cfcomponent output="false">
<cffunction name="getData" access="remote" output="false" returntype="struct">
<cfargument name="page" type="numeric" required="true" />
<cfargument name="pageSize" type="numeric" required="true" />
<cfargument name="gridsortcolumn" type="string" required="true" />
<cfargument name="gridsortdirection" type="string" required="true" />
<cfquery datasource="crabForms" name="sheets">
SELECT formID, region, title, sheetFileName, dateModified, description
FROM dbo.worksheets
order by Region
<cfif Arguments.gridsortcolumn NEQ "" AND Arguments.gridsortdirection NEQ "">
ORDER BY #gridsortcolumn# #gridsortdirection#
</cfif>
</cfquery>
<cfreturn queryConvertForGrid(sheets, Arguments.Page, Arguments.PageSize) />
</cffunction>
<!---EDIT A WORKSHEET--->
<cffunction name="editsheets" access="remote">
<cfargument name="gridaction" type="string" required="yes">
<cfargument name="gridrow" type="struct" required="yes">
<cfargument name="gridchanged" type="struct" required="yes">
<!---LOCAL VARIABLES--->
<cfset var colname="">
<cfset var value"">
<!---GRID PROCESSING--->
<CFSWITCH expression="#Arguments.gridaction#">
<!--- Process Update--->
<cfcase value="U">
<!---Get column name and value--->
<cfset colname=StructKeyList(Arguments.gridchanged)>
<cfset value=Arguments.gridchanged[colname]>
<!---Perform actual update--->
<cfquery datasource="#THIS.dsn#">
Update dbo.worksheets
SET #colname# = '#value#'
WHERE formid= #ARGUMENTS.gridrow.formid#
</cfquery>
</cfcase>
<!---PROCESS DELETES--->
<cfcase value="D">
<!--- Perform Actual Delete--->
<cfquery datasource="THIS.dsn">
DELETE FROM dbo.worksheets
where formID=#Arguments.gridrow.formID#
</cfquery>
</cfcase>
</CFSWITCH>
</cffunction>
GRID CODE______________
<cfform>
<!---Set grid and column names/headers and specify if editable--->
<cfgrid name="sheets"
bind="cfc:forms3.getData({cfgridpage}, {cfgridpagesize}, {cfgridsortcolumn},{cfgridSortDirection})"
onchange="cfc:forms3.editsheets({cfgridaction}, <cfgridrow},{cfgridchanged})"
format="html"
striperowcolor="##FFFFCC"
striperows="yes"
title="Worksheets"
pagesize="20"
selectmode="edit"
>
<cfgridcolumn name="formID" header="formID" display="no">
<cfgridcolumn name="region" header="Region"select="yes" width="150">
<cfgridcolumn name="title" header="Title" select="yes" width="125">
<cfgridcolumn name="sheetFileName" header="FileName"select="yes" width="200">
<cfgridcolumn name="dateModified" header="Date"select="yes" width="200">
</cfgrid>
</cfform>
Copy link to clipboard
Copied
I think the error is telling you that if cannot find cfc/forms3.cfc from the location where your docuemnt is running. I'm always fighting with dot paths - I hate them. I don't know if that helps you or not.
Myself, I tend to stay away from cfgrid and instead learned how to use jqgrid -- a plug-in for jquery. There are several examples around and once you know it, you'll be able to plop grids around wherever you want. Another big advantage is that as CF patches come out, the jqgrid code keeps working whereas I did have a CF patch break my cfgrid code (and my cfform validation code as well, thus my switch th jquery.validation). It took me about 3-5 days to really learn jqgrid and it was worth it in the long run. Hope this helps.
Copy link to clipboard
Copied
Thanks I will take a look at jgrid!
Copy link to clipboard
Copied
Is the CFC saved as the file form3.cfc? Within the same directory as the page containing the cfgrid? Your code seems to suggest so.
It is usually safest to start from the root when using the dotted notation. Suppose your CFC is the file C:\ColdFusion9\wwwroot\myDir\test\worksheet\form3.cfc. Then bind the grid to:
bind="cfc:myDir.test.worksheet.form3.getData(... etc., etc.)"
If your ColdFusion version is 9.0.1 or above, you will find that there is an even easier way to do this. Since 9.0.1, you can store your CFCs anywhere you like, even outside the web root.
Suppose, for example, you're on 9.0.1 and you've stored form3.cfc in the directory C:\myApps\cf_components. Then you could proceed as follows.
Declare the following in your Application.cfc:
<cfset this.mappings["/mycfc"] = "C:\myApps\cf_components\">
The grid would then bind to:
bind="cfc:mycfc.form3.getData(... etc., etc.)"