
829
DEVELOPING
COLDFUSION 9 APPLICATIONS
Requesting and Presenting Information
Las
t
upda
te
d 8/5/2010
To update or delete data dynamically, do the following:
•
Specify
selectmode="edit"
in the
cfgrid
tag. This lets the user edit the grid.
•
Specify an
onChange
attribute in the
cfgrid
tag. The attribute must use a bind expression to specify a CFC method,
JavaScript function, or URL of a page that updates the data source. The bind expression has the same format as the
bind expression described in “
Dynamically filling form data
” on page 825; however, it must take the following bind
parameters that the grid automatically passes. These parameters send information about the grid and its state to the
onChange
function.
When you update data dynamically, you can also use the
onError
attribute to specify the name of a JavaScript function
to handle any errors that result in a CFC or URL returning an HTTP error status. The method must take two
parameters: the HTTP error code and a text message that describes the error. The following example shows an
onError
handler function:
<script type="text/javascript">
function errorhandler(id,message) {
alert("Error while updating \n Error code: "+id+" \nMessage:
"+message);}
</script>
The following
example
displays the members of a department and lets users edit the data in the fields. When the focus
leaves the edited field an onChange event triggers and the form calls the
editData
CFC function to update the data
source.
Parameter name
Description
cfgridaction
The action performed on the grid. 'U' for update, or 'D' for delete.
cfgridrow
A structure or JavaScript Object whose keys are the column names and values are the original values
of the updated or deleted row.
cfgridchanged
A structure or JavaScript Object with a single entry, whose key is the name of the column with the
changed value, and whose value is the new value of the field. If the grid action is delete, this structure
exists but is empty.