Whatever message this page gives is out now! Go check it out!
Action | Procedure |
Sorting grid rows | Double-click the column header to sort a column in ascending order. Double-click again to sort the rows in descending order. |
Rearranging columns | Click any column heading and drag the column to a new position. |
Determining editable grid areas | When you click an editable cell, it is surrounded by a yellow box. |
Determining noneditable grid areas | When you click a cell (or row or column) that you cannot edit, its background color changes. The default color is salmon pink. |
Editing a grid cell | Double-click the cell. Press Return when you finish entering the data. |
Deleting a row | Click any cell in the row and click the Delete button. (Not available in Flash format grids.) |
Inserting a row | Click the Insert button. An empty row appears at the bottom of the grid. To enter a value in each cell, double-click the cell, enter the value, and click Return. (Not available in Flash format grids.) |
<cfquery name="empdata" datasource="cfdocexamples">
SELECT * FROM Employee
</cfquery>
<cfform name="Form1" action="submit.cfm" >
<cfgrid name="employee_grid" query="empdata"
selectmode="single">
<cfgridcolumn name="Emp_ID">
<cfgridcolumn name="LastName">
<cfgridcolumn name="Dept_ID">
</cfgrid>
<br>
<cfinput name="submitit" type="Submit" value="Submit">
</cfform>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. |
Array name | Description |
gridname.colname | Stores the new values of inserted, deleted, or updated cells. (Entries for deleted cells contain empty strings.) |
gridname.Original.colname | Stores the original values of inserted, deleted, or updated cells. |
gridname.RowStatus.Action | Stores the type of change made to the grid rows: D for delete, I for insert, or U for update. |
Form.mygrid.col1
Form.mygrid.col2
Form.mygrid.col3
Form.mygrid.original.col1
Form.mygrid.original.col2
Form.mygrid.original.col3
Form.mygrid.RowStatus.ActionForm.mygrid.RowStatus.Action[1] Form.mygrid.col2[1] Form.mygrid.original.col2[1] |
Form.mygrid.RowStatus.Action[1]
Form.mygrid.col1[1]
Form.mygrid.original.col1[1]
Form.mygrid.col3[1]
Form.mygrid.original.col3[1]
Form.mygrid.RowStatus.Action[2]
Form.mygrid.col2[2]
Form.mygrid.original.col2[2]<cfquery name="empdata" datasource="cfdocexamples">
SELECT * FROM Employee
</cfquery>
<cfform name="GridForm"
action="handle_grid.cfm">
<cfgrid name="employee_grid"
height=425
width=300
vspace=10
selectmode="edit"
query="empdata"
insert="Yes"
delete="Yes">
<cfgridcolumn name="Emp_ID"
header="Emp ID"
width=50
headeralign="center"
headerbold="Yes"
select="No">
<cfgridcolumn name="LastName"
header="Last Name"
width=100
headeralign="center"
headerbold="Yes">
<cfgridcolumn name="Dept_ID"
header="Dept"
width=35
headeralign="center"
headerbold="Yes">
</cfgrid>
<br>
<cfinput name="submitit" type="Submit" value="Submit">
</cfform>Code | Description |
<cfgrid name="employee_grid"
height=425
width=300
vspace=10
selectmode="edit"
query="empdata"
insert="Yes"
delete="Yes">Populates a cfgrid control with data from the empdata query. Selecting a grid cell enables you to edit it. You can insert and delete rows. The grid is 425 X 300 pixels and has 10 pixels of space above and below it. | ||
<cfgridcolumn name="Emp_ID"
header="Emp ID"
width=50
headeralign="center"
headerbold="Yes"
select="No">Creates a 50-pixel wide column for the data in the Emp_ID column of the data source. Centers a header named Emp ID and makes it bold. Does not allow users to select fields in this column for editing. Since this field is the table's primary key, users should not be able to change it for existing records, and the DBMS should generate this field as an autoincrement value. | ||
<cfgridcolumn name="LastName"
header="Last Name"
width=100
headeralign="center"
headerbold="Yes">Creates a 100-pixel wide column for the data in the LastName column of the data source. Centers a header named Last Name and makes it bold. | ||
<cfgridcolumn name="Dept_ID"
header="Dept"
width=35
headeralign="center"
headerbold="Yes">Creates a 35-pixel wide column for the data in the Dept_ID column of the data source. Centers a header named Dept and makes it bold. |
<html>
<head>
<title>Update grid values</title>
</head>
<body>
<h3>Updating grid using cfgridupdate tag.</h3>
<cfgridupdate grid="employee_grid"
datasource="cfdocexamples"
tablename="Employee">
Click <a href="grid2.cfm">here</a> to display updated grid.
</body>
</html>To update a grid cell, modify the cell contents, and then press Return. |
Code | Description |
<cfgridupdate grid="employee_grid" | Updates the database from the Employee_grid grid. |
datasource="cfdocexamples" | Updates the cfdocexamples data source. |
tablename="Employee" | Updates the Employee table. |
<html> <head> <title>Catch submitted grid values</title> </head> <body> <h3>Grid values for Form.employee_grid row updates</h3> <cfif isdefined("Form.employee_grid.rowstatus.action")> <cfloop index = "counter" from = "1" to = #arraylen(Form.employee_grid.rowstatus.action)#> <cfoutput> The row action for #counter# is: #Form.employee_grid.rowstatus.action[counter]# <br> </cfoutput> <cfif Form.employee_grid.rowstatus.action[counter] is "D"> <cfquery name="DeleteExistingEmployee" datasource="cfdocexamples"> DELETE FROM Employee WHERE Emp_ID=<cfqueryparam value="#Form.employee_grid.original.Emp_ID[counter]#" CFSQLType="CF_SQL_INTEGER" > </cfquery> <cfelseif Form.employee_grid.rowstatus.action[counter] is "U"> <cfquery name="UpdateExistingEmployee" datasource="cfdocexamples"> UPDATE Employee SET LastName=<cfqueryparam value="#Form.employee_grid.LastName[counter]#" CFSQLType="CF_SQL_VARCHAR" >, Dept_ID=<cfqueryparam value="#Form.employee_grid.Dept_ID[counter]#" CFSQLType="CF_SQL_INTEGER" > WHERE Emp_ID=<cfqueryparam value="#Form.employee_grid.original.Emp_ID[counter]#" CFSQLType="CF_SQL_INTEGER"> </cfquery> <cfelseif Form.employee_grid.rowstatus.action[counter] is "I"> <cfquery name="InsertNewEmployee" datasource="cfdocexamples"> INSERT into Employee (LastName, Dept_ID) VALUES (<cfqueryparam value="#Form.employee_grid.LastName[counter]#" CFSQLType="CF_SQL_VARCHAR" >, <cfqueryparam value="#Form.employee_grid.Dept_ID[counter]#" CFSQLType="CF_SQL_INTEGER" >) </cfquery> </cfif> </cfloop> </cfif> Click <a href="grid2.cfm">here</a> to display updated grid. </body> </html> |
Code | Description |
<cfif isdefined("Form.employee_grid.rowstatus.action")>
<cfloop index = "counter" from = "1" to = #arraylen(Form.employee_grid.rowstatus.action)#>If there is an array of edit types, changes the table. Otherwise, does nothing. Loops through the remaining code once for each row to be changed. The counter variable is the common index into the arrays of change information for the row being changed. | ||
<cfoutput>
The row action for #counter# is:
#Form.employee_grid.rowstatus.action[counter]#
<br>
</cfoutput>Displays the action code for this row: U for update, I for insert, or D for delete. | ||
<cfif Form.employee_grid.rowstatus.action[counter] is "D">
<cfquery name="DeleteExistingEmployee"
datasource="cfdocexamples">
DELETE FROM Employee
WHERE Emp_ID=<cfqueryparam value="#Form.employee_grid.original.Emp_ID[counter]#"
CFSQLType="CF_SQL_INTEGER" >
</cfquery>If the action is to delete a row, generates a SQL DELETE query specifying the Emp_ID (the primary key) of the row to be deleted. | ||
<cfelseif Form.employee_grid.rowstatus.action[counter] is "U">
<cfquery name="UpdateExistingEmployee"
datasource="cfdocexamples">
UPDATE Employee
SET
LastName=<cfqueryparam
value="#Form.employee_grid.LastName[counter]#"
CFSQLType="CF_SQL_VARCHAR" >,
Dept_ID=<cfqueryparam
value="#Form.employee_grid.Dept_ID[counter]#"
CFSQLType="CF_SQL_INTEGER" >
WHERE Emp_ID=<cfqueryparam
value="#Form.employee_grid.original.Emp_ID[counter]#"
CFSQLType="CF_SQL_INTEGER">
</cfquery>Otherwise, if the action is to update a row, generates a SQL UPDATE query to update the LastName and Dept_ID fields for the row specified by the Emp_ID primary table key. | ||
<cfelseif Form.employee_grid.rowstatus.action[counter] is "I">
<cfquery name="InsertNewEmployee"
datasource="cfdocexamples">
INSERT into Employee (LastName, Dept_ID)
VALUES (<cfqueryparam
value="#Form.employee_grid.LastName[counter]#"
CFSQLType="CF_SQL_VARCHAR" >,
<cfqueryparam value="#Form.employee_grid.Dept_ID[counter]#"
CFSQLType="CF_SQL_INTEGER" >)
</cfquery>Otherwise, if the action is to insert a row, generates a SQL INSERT query to insert the employee's last name and department ID from the grid row into the database. The INSERT statement assumes that the DBMS automatically increments the Emp_ID primary key. If you use the version of the cfdocexamples database that is provided for UNIX installations, the record is inserted without an Emp_ID number. | ||
</cfif>
</cfloop>
</cfif>Closes the cfif tag used to select among deleting, updating, and inserting.Closes the loop used for each row to be changed.Closes the cfif tag that surrounds all the active code. |