Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CFGrid - Delete Options

Status
Not open for further replies.

pathetic

Programmer
Joined
Dec 3, 2004
Messages
74
Location
US
Is there an option to allow deleting multiple entries with CFGrid, possibly insert a column containing checkboxes and when selected allows multiple delete? How would I write this?

CFGrid has hyperlinked files, these files reside on my webserver. With the delete option, how can I not only delete the data from the CFGrid but also delete the file on the webserver?


Thank you.

 
hi pathetic,

I don't know about using the checkboxes to allow for multiple deletes, but if you use the attribute selectMode="edit", you should be able to edit and\or remove data from the grid. When you submit the form that the grid resides in, Coldfusion will return 3 arrays. Once you have this data you can iterate through the arrays and use the values (the file name) to physicaly delete the files from your server. The 3 arrays returned are:

form.GridName.ColumnName
form.GridName.original.ColumnName
form.GridName.RowStatus.Action

* where GridName and ColumnName are the actual names that you defined in the grid.

So to physically remove your files, try something like this on your form's action page:

Code:
<!--- Assuming the values in the grid cell is just a file name --->
<!--- Store the absolute path to the location of the files to delete --->
<cfset myFilePath = "c:\[URL unfurl="true"]wwwroot\myapp\myfiles\">[/URL]

<!--- Determine if any rows were returned --->
<cfif NOT isDefined("form.GridName.ColumnName") OR NOT isArray(form.GridName.ColumnName)>
	
	<!--- There were no rows to take action on --->
	<!--- do some action --->
	
<cfelse>
	
	<!--- record the number of rows returned --->
	<cfset numOfRows = arraylen(form.GridName.ColumnName)>

	<!--- loop through the rows returned from the grid --->
	<cfloop from="1" to="#numOfRows#" index="i">	
		
		<!--- If any rows were 'deleted' then try and remove the file --->
		<cfif form.GridName.RowStatus.Action[i] IS "delete">
			<cfif fileExists(myFilePath &"\"& form.GridName.original.ColumnName[i])>
			<cftry>
				<cflock name="deleteFileLock" timeout="10" throwontimeout="Yes" type="EXCLUSIVE">
					<cffile action="delete" file="#myFilePath#\#form.GridName.original.ColumnName[i]#" >
				</cflock>
				<cfcatch type="any">
					<!--- Removing the file failed. Do some action --->
				</cfcatch>
			</cftry>			
			</cfif>
		</cfif>
		
	</cfloop>
	
</cfif>

I hope this helps,

jalpino
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top