My client's application has a Coldfusion HTML form that contains a Coldfusion
HTML grid which binds to a cfc to retrieve and update the grid's data. My
client would like one of the grids columns to have an autosuggest feature like
the other input fields on the page has. (he wants to be able to start typing
and see a list of things that he's typed in there before) I've found some
scripts that will apply the autosuggest feature to an input field (which
doesn't seem necessary since it's built into the browser anyway) but I can't
get it to work from within the grid. (I tried to simply change the path and
field name of the input to the path and column name of the grid, but that
didn't work) I also saw an article that said you can set a grid column's
control type to type="combobox", but when I try that, it throws up an error
stating that "Bind expressions cannot be empty". (perhaps because it doesn't
know where to get the data to populate the drop-down list from) My client is
very adamant about having this feature, so I can't just tell him that it isn't
possible. (he doesn't believe in "it can't be done") Here is the code for the
grid and the cfc that it's bound to, I really hope someone can help me with
this.
Grid code:
<cfgrid name="grdProjectDetails" format="html" width="820" selectMode="edit"
insert="yes" delete="yes" italic="no" bold="no" gridLines="yes"
colHeaders="yes" colHeaderItalic="no" colHeaderBold="yes" enabled="Yes"
visible="Yes" rowheaders="no" bindonload="yes"
bind="cfc:editGrid.fnGetGridDetails({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})"
onchange="cfc:editGrid.fnEditGridDetails({cfgridaction},{cfgridrow},{cfgridchanged})">
<cfgridcolumn name="DetailID" display="no">
<cfgridcolumn name="ProjectID" display="no">
<cfgridcolumn name="Quantity" header="Qty." Select="Yes" width="50"
textcolor="##003366" bold="No" dataalign="left" headeralign="center"
headerbold="yes" headertextcolor="##003366">
<cfgridcolumn name="TaskName" header="Description" Select="Yes" width="600"
textcolor="##003366" bold="No" dataalign="left" headeralign="center"
headerbold="yes" headertextcolor="##003366">
<cfgridcolumn name="UnitPrice" header="Unit Price" select="Yes" width="100"
textcolor="##003366" bold="No" dataalign="left" headeralign="center"
headerbold="yes" headertextcolor="##003366">
<cfgridcolumn name="ExtendedPrice" header="Total Cost" select="Yes"
width="100" textcolor="##003366" bold="No" dataalign="left"
headeralign="center" headerbold="yes" headertextcolor="##003366">
</cfgrid>
cfc code (editGrid.cfc):
<cffunction name="fnGetGridDetails" access="remote" returntype="any">
<cfargument name="page" type="numeric" required="no">
<cfargument name="pageSize" type="numeric" required="no">
<cfargument name="gridsortcolumn" type="string" required="no" default="">
<cfargument name="gridsortdir" type="string" required="no" default="">
<cfquery name="qGetGridDetails" datasource="#Application.Datasource#">
SELECT *
FROM tblProjectDetails
WHERE ProjectID=#session.pid#
<cfif ARGUMENTS.gridsortcolumn NEQ "" AND ARGUMENTS.gridsortdir NEQ
"">ORDER BY #ARGUMENTS.gridsortcolumn# #ARGUMENTS.gridsortdir#</cfif>
</cfquery>
<cfreturn QueryConvertForGrid(qGetGridDetails, ARGUMENTS.page,
ARGUMENTS.pageSize)>
</cffunction>
<cffunction name="fnEditGridDetails" access="remote">
<cfargument name="gridaction" type="string" required="yes">
<cfargument name="gridrow" type="struct" required="yes">
<cfargument name="gridchanged" type="struct" required="yes">
<cfset var qAddProjectDetail="">
<cfset var qUpdateProjectDetail="">
<cfset var qDeleteProjectDetail="">
<cfif IsStruct(arguments.gridrow) and IsStruct(arguments.gridchanged)>
<cfif arguments.gridaction is "I">
<cfquery name="qAddProjectDetail" datasource="#Application.Datasource#">
INSERT INTO tblProjectDetails (ProjectID, Quantity, TaskName, UnitPrice,
ExtendedPrice)
VALUES (#session.pid#, #arguments.gridrow.Quantity#,
'#arguments.gridrow.TaskName#', #arguments.gridrow.UnitPrice#,
#arguments.gridrow.Quantity#*#arguments.gridrow.UnitPrice#)
</cfquery>
<cfelseif arguments.gridaction is "U">
<cfset var colname=StructKeyList(arguments.gridchanged)>
<cfset var value=StructFind(arguments.gridchanged, colname)>
<cfquery name="qUpdateProjectDetail" datasource="#Application.Datasource#">
UPDATE tblProjectDetails
SET #colname#="#value#"
WHERE DetailID=<cfqueryparam cfsqltype="cf_sql_integer"
value="#arguments.gridrow.DetailID#">
</cfquery>
<cfelseif arguments.gridaction is "D">
<cfquery name="qDeleteProjectDetail" datasource="#Application.Datasource#">
DELETE FROM tblProjectDetails
WHERE DetailID=<cfqueryparam cfsqltype="cf_sql_integer"
value="#arguments.gridrow.DetailID#">
</cfquery>
</cfif>
<cfquery name="qGetExtendedPrice" datasource="#Application.Datasource#">
SELECT *
FROM vTempDetails
WHERE ProjectID=#session.pid#
</cfquery>
<cfloop query="qGetExtendedPrice">
<cfquery name="qUpdateExtendedPrice" datasource="#Application.Datasource#">
UPDATE tblProjectDetails
SET ExtendedPrice=#qGetExtendedPrice.Quantity#*#qGetExtendedPrice.UnitPrice#
WHERE DetailID=#qGetExtendedPrice.DetailID#
</cfquery>
</cfloop>
</cfif>
</cffunction>
<cffunction name="fnCalculateSubtotal" access="remote" returntype="any">
<cfquery name="qGetSubtotal" datasource="#Application.Datasource#">
SELECT SUM(ExtendedPrice) AS Subtotal
FROM vTempDetails
WHERE ProjectID=#session.pid#
</cfquery>
<cfset Subtotal=#DollarFormat(ValueList(qGetSubtotal.Subtotal))#>
<cfreturn Subtotal>
</cffunction>
<cffunction name="fnChangeTaxable" access="remote">
<cfif session.Taxable IS 1>
<cfset Taxable=0>
<cfelseif session.Taxable IS 0>
<cfset Taxable=1>
</cfif>
<cfquery name="qUpdateTaxable" datasource="#Application.Datasource#">
UPDATE tblProjectDetails
SET Taxable=#Taxable#
</cfquery>
</cffunction>
<cffunction name="fnCalculateTax" access="remote" returntype="any">
<cfquery name="qGetTaxable" datasource="#Application.Datasource#">
SELECT SUM(ExtendedPrice) AS Taxable
FROM vTempDetails
WHERE ProjectID=#session.pid#
</cfquery>
<cfset StartingTotal=#ValueList(qGetTaxable.Taxable)#>
<cfset Tax=#StartingTotal#*#Application.SalesTax#>
<cfif isDefined("session.Taxable") AND session.Taxable IS 1>
<cfset TotalTax=#DollarFormat(Tax)#>
<cfelse>
<cfset TotalTax=#DollarFormat(0)#>
</cfif>
<cfreturn TotalTax>
</cffunction>
<cffunction name="fnCalculateTotal" access="remote" returntype="any">
<cfquery name="qGetTotal" datasource="#Application.Datasource#">
SELECT SUM(ExtendedPrice) AS Total
FROM vTempDetails
WHERE ProjectID=#session.pid#
</cfquery>
<cfset BeginningTotal=#ValueList(qGetTotal.Total)#>
<cfset SalesTax=#BeginningTotal#*#Application.SalesTax#>
<cfif isDefined("session.Taxable") AND session.Taxable IS 1>
<cfset NewTotal=#BeginningTotal#+#SalesTax#>
<cfelse>
<cfset NewTotal=#BeginningTotal#>
</cfif>
<cfset Total=#DollarFormat(NewTotal)#>
<cfreturn Total>
</cffunction>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:351818
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm