Solved

How to insert data into a CFGRID

Posted on 2013-10-24
5
594 Views
Last Modified: 2013-10-30
I am using this method from Ben Forta to create a grid that allows edits and deletes. I would also like the ability to use insert="yes" on the grid but I cannot get it working. Could someone assist? The insert button appears but I do not know how to send the newly entered information to the .cfc properly. Below is what I have so far with a "cfcase" of "I".

Page/Form:
<cfwindow initshow="true" center="true"
			width="430" height="340" title="Artists">

<cfform>
	<cfgrid name="artists"
			format="html"
			pagesize="10"
			striperows="yes"
			selectmode="edit"
                                                insert="yes"
			delete="yes"
			bind="cfc:artists.getArtists({cfgridpage},
										{cfgridpagesize},
										{cfgridsortcolumn},
										{cfgridsortdirection})"
			onchange="cfc:artists.editArtist({cfgridaction},
											{cfgridrow},
											{cfgridchanged})">
		<cfgridcolumn name="is" display="false" />
		<cfgridcolumn name="lastname" header="Last Name" width="100"/>
		<cfgridcolumn name="firstname" header="First Name" width="100"/>
		<cfgridcolumn name="email" header="E-Mail" width="200"/>
	</cfgrid>
</cfform>

</cfwindow>

Open in new window


CFC:
<cfcomponent output="false">


	<cfset THIS.dsn="cfartgallery">


	<!--- Get artists --->
	<cffunction name="getArtists" access="remote" returntype="struct">
		<cfargument name="page" type="numeric" required="yes">
		<cfargument name="pageSize" type="numeric" required="yes">
		<cfargument name="gridsortcolumn" type="string" required="no" default="">
		<cfargument name="gridsortdir" type="string" required="no" default="">

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

		<!--- Get data --->
		<cfquery name="artists" datasource="#THIS.dsn#">
		SELECT artistid, lastname, firstname, email 
		FROM artists
		<cfif ARGUMENTS.gridsortcolumn NEQ ""
			and ARGUMENTS.gridsortdir NEQ "">
			ORDER BY #ARGUMENTS.gridsortcolumn# #ARGUMENTS.gridsortdir#
		</cfif>
		</cfquery>

		<!--- And return it as a grid structure --->
		<cfreturn QueryConvertForGrid(artists,
							ARGUMENTS.page,
							ARGUMENTS.pageSize)>
	</cffunction>


	<!--- Edit an artist --->
	<cffunction name="editArtist" 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="">

		<!--- Process gridaction --->
		<cfswitch expression="#ARGUMENTS.gridaction#">
			<!--- Process updates --->
			<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 artists
				SET #colname# = '#value#'
				WHERE artistid = #ARGUMENTS.gridrow.artistid#
				</cfquery>
			</cfcase>
			<!--- Process deletes --->
			<cfcase value="D">
				<!--- Perform actual delete --->
				<cfquery datasource="#THIS.dsn#">
				DELETE FROM artists
				WHERE artistid = #ARGUMENTS.gridrow.artistid#
				</cfquery>
			</cfcase>
			<cfcase value="I">
				<!--- Perform insert--->
				<cfquery datasource="#THIS.dsn#">
				Insert Into artists.................
								</cfquery>
			</cfcase>

		</cfswitch>
	</cffunction>


</cfcomponent>

Open in new window

Any help would be greatly appreciated.
0
Comment
Question by:earwig75
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 16

Expert Comment

by:Gurpreet Singh Randhawa
ID: 39599544
If you are using Coldfusion 8, Check this CRUD operations [Create, read, Update, Delete]

http://www.anujgakhar.com/2008/03/18/crud-with-cfgrid-html-format/

Hre is another link as CFGrid Uses EXT JS 3 as its engine for cf9

http://www.coldfusion-ria.com/Blog/index.cfm/2009/12/14/ExtJS-30-Editor-Grid-with-ColdFusion

let me know which coldfusion version you are using
0
 

Author Comment

by:earwig75
ID: 39600381
I am using CF9 and would like to do this without relying on an ext hack or whatever. I know CF9 has the functionality built in but I can't seem to get it working.
0
 

Accepted Solution

by:
earwig75 earned 0 total points
ID: 39600463
I got this working. Added the below to my function:
<cfcase value="I">
<cfquery name="insertRow">
                INSERT INTO RECORDS (ROW_ID, ROW_COL1,ROW_COL2)
VALUES ('#gridrow.ROW_ID#',
'#gridrow.ROW_COL1#',
'#gridrow.ROW_COL2#'
)
</cfcase>

Open in new window

0
 
LVL 16

Expert Comment

by:Gurpreet Singh Randhawa
ID: 39602324
great but the inbuild does not have that many features what ext js allows you and its not a hack with ext js, actually its a underlying structure of cfgrid and eventually the usage of ext JS causes the CFGRID to work awesome, the way you did is very traditional

Cheers
0
 

Author Closing Comment

by:earwig75
ID: 39611020
I found a solution to allow inserts. This works perfectly.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question