I am following this guide on creating an editable cfgrid : CFGRID GUIDE
However, I am running into an error where it's saying cfgridupdate cannot find the gridname docgrid but I can't see where this could be caused. I have a page called handle_grid.cfm, which will run one of two queries to update data. Can someone spot what I might be missing here?
Master_Doc_Maint.cfm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<!-- Importing jquery libraries -->
<title>Master List Maintenance</title>
<!--- Make sure the person running is an admin. --->
<cfif NOT listfindnocase(application.admins,application.wsl_cdsid)>
Sorry. You are not listed as an admin.
<cfabort>
</cfif>
<!--- Get all the data from the database. --->
<cfquery datasource="mydatastore name="get_all_docs">
SELECT SITE,SECTIONS,TAB,DOC_NUMBER,DESCRIPTION,REV_LEVEL,REVISION_DATE,REVIEW_DATE,ADMIN,ACTIVE from MDL_MASTER_LIST
ORDER BY SITE,sections,TAB,DOC_NUMBER
</cfquery>
<cfform name="docgrid" action="handle_grid.cfm" > <!-- calls the handle program to process the changed data -->
<cfgrid name="doclist" align="Top" autowidth="yes" bgcolor="FFF" colheaderbold="yes" selectmode="edit"
format="html" griddataalign="left" gridlines="yes" query="get_all_docs" sort="yes" striperowcolor="FC6" striperows="yes"
width=1650 insert="Yes" delete="yes">
<cfgridcolumn name="Site" width="100">
<cfgridcolumn name="Sections" width="100">
<cfgridcolumn name="Doc_Number" width="100" select="No">
<cfgridcolumn name="Description" width="300">
<cfgridcolumn name="Rev_Level" width="100">
<cfgridcolumn name="Revision_Date" width="100">
<cfgridcolumn name="Review_Date" width="100">
<cfgridcolumn name="Admin" width="100">
<cfgridcolumn name="Active" width="100">
</cfgrid>
<br>
<cfinput name="UpdateDocs" type="Submit" value="Update">
</cfform>
<cfgridupdate grid="doclist"
datasource="mydatastore"
tablename="MDL_MASTER_LIST">
Click <a href="Master_Doc_Maint.cfm">here</a> to display updated grid.
</head>
<body>
</body>
</html>
handle_grid.cfm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Master List Maintenance</title>
</head>
<!--- Make sure the person running is an admin. --->
<cfif NOT listfindnocase(application.admins,application.wsl_cdsid)>
Sorry. You are not listed as an admin.
<cfabort>
</cfif>
<body>
<h3>Grid values for Form.firstgrid row updates</h3>
<cfif isdefined("Form.docgrid.rowstatus.action") is True>
<cfloop index = "counter" from = "1" to =
#arraylen(Form.docgrid.rowstatus.action)#>
<cfoutput>
The row action for #counter# is:
#Form.docgrid.rowstatus.action[counter]#
<br>
</cfoutput>
<cfswitch expression="#Form.docgrid.rowstatus.action[counter]#">
<cfcase value = "U">
<cfquery name="query_insert" datasource="mydatastore">
UPDATE MDL_MASTER_LIST
SET
active = <cfqueryparam value = '#form.docgrid.active[counter]#' CFSQLType="CF_SQL_VARCHAR">,
admin = <cfqueryparam value = '#form.docgrid.admin[counter]#' CFSQLType="CF_SQL_VARCHAR">,
description = <cfqueryparam value = '#form.docgrid.description[counter]#' CFSQLType="CF_SQL_VARCHAR">,
doc_number = <cfqueryparam value = '#form.docgrid.doc_number[counter]#' CFSQLType="CF_SQL_VARCHAR">,
is_contact = <cfqueryparam value = #form.docgrid.is_contact[counter]# CFSQLType="CF_SQL_VARCHAR">,
is_file = <cfqueryparam value = #form.docgrid.is_file[counter]# CFSQLType="CF_SQL_VARCHAR">,
review_date = <cfqueryparam value = #createodbcdate(form.docgrid.review_date[counter])# CFSQLType="CF_SQL_DATE">,
revision_date = <cfqueryparam value = #createodbcdate(form.docgrid.revision_date[counter])# CFSQLType="CF_SQL_DATE">,
rev_level = <cfqueryparam value = '#form.docgrid.rev_level[counter]#' CFSQLType="CF_SQL_VARCHAR">,
sections = <cfqueryparam value = '#form.docgrid.sections[counter]#' CFSQLType="CF_SQL_VARCHAR">,
site = <cfqueryparam value = '#form.docgrid.site[counter]#' CFSQLType="CF_SQL_VARCHAR">,
tab = <cfqueryparam value = '#form.docgrid.tab[counter]#' CFSQLType="CF_SQL_VARCHAR">
WHERE doc_number = <cfqueryparam value = '#form.docgrid.original.doc_number[counter]#' CFSQLType="CF_SQL_VARCHAR">
</cfquery>
</cfcase>
<cfcase value ="D">
<cfquery name="query_delete" datasource="mydatastore">
DELETE FROM MDL_MASTER_LIST WHERE doc_number = <cfqueryparam value = '#form.docgrid.original.doc_number[counter]#' CFSQLType="CF_SQL_VARCHAR">
</cfquery>
</cfcase>'
</cfswitch>
</cfloop>
</cfif>
Click <a href="Master_Doc_Maint.cfm">here</a> to display updated grid.
</body>
</html>
In your link to the CFGRID docs:
Under "Creating an editable grid":
This seems that the
cfgridupdatestatement should be on a separate page from thecfgrid. You should have the page with the grid, edits would post to the page withcfgridupdate. You have them both on the same page.To reiterate Adam's comment,
CFGRIDand the other CF UI controls are straight trash compared to modern UI libraries. If this is new code, I would recommend replacing this grid with one of these:Update:
https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-g-h/cfgridupdate.html
There's an example here that shows a condition check before using
cfgridupdate.