User Guide

Table Of Contents
Creating data grids with the cfgrid tag 647
Reviewing the code
The following table describes the highlighted code and its function:
Creating an editable grid
You can build grids to allow users to edit data within them. Users can edit individual cell data, as
well as insert, update, or delete rows. To enable grid editing, you specify
selectmode="edit" in
the
cfgrid tag.
You can let users add or delete grid rows by setting the
insert or delete attributes in the cfgrid
tag to Yes. Setting the
insert and delete attribute to Yes causes the cfgrid tag to display Insert
and Delete buttons as part of the grid, as the following figure shows:
You can use a grid in two ways to make changes to your ColdFusion data sources:
Create a page to which you pass the cfgrid form variables. In that page, perform cfquery
operations to update data source records based on the form values returned by the
cfgrid tag.
Pass grid edits to a page that includes the cfgridupdate tag, which automatically extracts the
form variable values and passes that data directly to the data source.
Using the
cfquery tag gives you complete control over interactions with your data source. The
cfgridupdate tag provides a much simpler interface for operations that do not require the same
level of control.
Code Description
<cfgrid name="employee_grid"
query="empdata"
Creates a grid named employee_grid and populate it with the
results of the query empdata.
If you specify a
cfgrid tag with a query attribute defined and
no corresponding
cfgridcolumn attributes, the grid contains
all the columns in the query.
selectmode="single">
Allows the user to select only one cell; does not allow editing.
Other modes are row, column, and edit.
<cfgridcolumn name="Emp_ID">
Puts the contents of the Emp_ID column in the query results in
the first column of the grid.
<cfgridcolumn name="LastName">
Puts the contents of the LastName column in the query
results in the second column of the grid.
<cfgridcolumn name="Dept_ID">
Puts the contents of the Dept_ID column in the query results
in the third column of the grid.