|
ColdFusion 9.0 Resources |
cfgridDescriptionUsed in the cfform tag. Puts a grid control (a table of data) in a ColdFusion form. To specify grid columns and row data, use the cfgridcolumn and cfgridrow tags, or use the query attribute, with or without cfgridcolumn tags. Syntax<cfgrid
name="name"
align="value"
appendKey="yes|no"
autoWidth="yes|no"
bgColor="web color"
bind="bind expression"
bindOnLoad="yes|no"
bold="yes|no"
colHeaderAlign="left|right|center"
colHeaderBold="yes|no"
colHeaderFont="font_name"
colHeaderFontSize="size"
colHeaderItalic="yes|no"
colHeaders="yes|no"
colHeaderTextColor="web color"
collapsible="false|true"
delete="yes|no"
deleteButton="text"
enabled="yes|no"
font="column_font"
fontSize="size"
format="applet|Flash|html|xml"
gridDataAlign="left|right|center"
gridLines="yes|no"
groupfield="column name"
height="integer"
highlightHref="yes|no"
href="URL"
hrefKey="column_name"
hSpace="integer"
insert="yes|no"
insertButton="text"
italic="yes|no"
maxRows="number"
notSupported="text"
onBlur="ActionScript"
onChange="ActionScript or bind expression"
onError="JavaScript function name"
onFocus="ActionScript function"
onLoad="JavaScript function name"
onValidate="JavaScript function name"
pageSize="number of rows"
pictureBar="yes|no"
preservePageOnSort="yes|no"
query="query name"
rowHeaderAlign="left|right|center"
rowHeaderBold="yes|no"
rowHeaderFont="font name"
rowHeaderFontSize="size"
rowHeaderItalic="yes|no"
rowHeaders="yes|no"
rowHeaderTextColor="web color"
rowHeight="pixels"
selectColor="web color"
selectMode="mode"
selectOnLoad="yes|no"
sort="yes|no"
sortAscendingButton="text"
sortDescendingButton="text"
stripeRowColor="web color"
stripeRows="yes|no"
style= "style specification"
target="URL_target"
textColor="web color"
title="text"
tooltip="text"
visible="yes|no"
vSpace="integer"
width="integer">
zero or more cfgridcolumn and cfgridrow tags
</cfgrid>
Note: You can specify
this tag’s attributes in an attributeCollection attribute
whose value is a structure. Specify the structure name in the attributeCollection attribute
and use the tag’s attribute names as structure keys.
See alsocfajaximport, cfapplet, cfcalendar, cfgridcolumn, cfgridrow, cfgridupdate, cfform, cfformgroup, cfformitem, cfinput, cfselect, cfslider, cftextarea, cftree, Using HTML grids in the Developing ColdFusion Applications HistoryColdFusion 9:
ColdFusion 8: Added support for HTML format grids, including the html value of the format attribute and the following attributes: bind, bindOnLoad, pageSize, preservePageOnSort, stripeRows, stripeRowColor. ColdFusion MX 7.01: Added support for the onBlur and onFocus events. ColdFusion MX 7:
ColdFusion MX: Changed the rowHeaderWidth attribute: ColdFusion does not use the rowHeaderWidth attribute. You can omit it. AttributesNote: In XML format, ColdFusion passes all attributes
to the XML. The supplied XSLT skins do not handle or display XML
format grids, but do display applet and Flash format grids.
UsageMost of the following paragraphs describe grid features that apply to all, or at least two, grid formats. For information that is specific to Flash forms, see Creating Forms in Flash in the Developing ColdFusion Applications. For information that is specific to HTML format grids, see Using HTML grids in the Developing ColdFusion Applications. This tag must be in a cfform tag block. An applet format grid requires the client to download a Java applet. Also, if the client does not have an up-to-date Java plug-in installed, the system might also have to download an updated Java plug-in to display an applet format grid. A Flash format grid generates a Flash control, and can be embedded in an HTML format cfform tag. For this tag to work properly in either Flash or applet format, the browser must also be JavaScript-enabled. Note: If
you specify Flash format for this tag in an HTML format form, and
you do not specify height and width attributes,
Flash takes up more than the remaining visible area on the screen.
If any other output follows the grid, including any form controls,
users must scroll to see it. Therefore, if you follow a Flash grid
in an HTML form with additional output, specify height and width values.
You can populate a cfgrid with data from a cfquery. If you do not specify any cfgridcolumn tags in the cfgrid body, ColdFusion generates a grid with the following:
This tag requires an end tag. Note: Clicking the submit
button while editing a grid cell occasionally causes the cell changes
to be lost. To ensure that changes are submitted properly, recommends
that after user updates data in a cell, they click another cell
before submitting the form.
Returning cfgrid data to the action pageThe following information applies to all cfgrid formats. Also, HTML format grids can dynamically get data by using a bind expression. For more information, see Using HTML grids in the Developing ColdFusion Applications. When a user submits a form, the cfgrid tag sends information about user actions by setting form variables in the data submitted to the form’s action page. Because the data can vary, depending on the tag’s SelectMode attribute value, the form variables that are returned also vary depending on this value. In general, the data returned falls into one of these categories:
Simple selection data (SelectMode = Single, Column, or Row)The data that form variables return to the cfform’s action page contains information about which cells the user selected. In general, ColdFusion makes this data available in the action page, as ColdFusion variables in the Form scope, with the naming convention form.#GridName#.#ColumnName#. Each SelectMode returns these form variables: SelectMode="single" form.#GridName#.#ColumnName# = "SelectedCellValue" SelectMode="column" form.#GridName#.#ColumnName# = "ValueOfCellRow1, ValueOfCellRow2, ValueOfCellRowN" SelectMode="row" form.#GridName#.#Column1Name# = "ValueOfCellInSelectedRow" form.#GridName#.#Column2Name# = "ValueOfCellInSelectedRow" form.#GridName#.#ColumnNName# = "ValueOfCellInSelectedRow" Complex update data (SelectMode = Edit)The grid returns a large amount of data, to inform the action page of inserts, updates, or deletes that the user made to the grid. In most cases, you can use the cfgridupdate tag to automatically gather the data from the form variables; the tag collects data, writes SQL calls, and updates the data source. If you cannot use cfgridupdate (if, for example, you must distribute the returned data to more than one data source), write code to read form variables. In this mode, ColdFusion creates the following array variables in the Form scope for each cfgrid: form.#GridName#.#ColumnName# form.#GridName#.original.#ColumnName# form.#GridName#.RowStatus.Action Each table row that contains an update, insert, or deletion has a parallel entry in each of these arrays. To view all the information for all the changes, you can traverse the arrays, as in this example. To make it work with a cfgrid on a submitted cfform, set the GridName variable to the name of the grid and the ColNameList to a list of the grid columns. <cfloop index="ColName" list="#ColNameList#">
<cfif IsDefined("form.#GridName#.#ColName#")>
<cfoutput><br>form.#GridName#.#ColName#:<br></cfoutput>
<cfset Array_New = form.[#GridName#][#ColName#]>
<cfset Array_Orig = form[#GridName#]['original'][#ColName#]>
<cfset Array_Action = form[#GridName#]RowStatus.Action>
<cfif NOT IsArray(Array_New)>
<b>The form variable is not an array!</b><br>
<cfelse>
<cfset size = ArrayLen(Array_New)>
<cfoutput>
Result Array Size is #size#.<br>
Contents:<br>
</cfoutput>
<cfif size IS 0>
<b>The array is empty.</b><br>
<cfelse>
<table BORDER="yes">
<tr>
<th>Loop Index</TH>
<th>Action</TH>
<th>Old Value</TH>
<th>New Value</TH>
</tr>
<cfloop index="LoopCount" from="1" to=#size#>
<cfset Val_Orig = Array_Orig[#LoopCount#]>
<cfset Val_New = Array_New[#LoopCount#]>
<cfset Val_Action = Array_Action[#LoopCount#]>
<cfoutput>
<tr>
<td>#LoopCount#</td>
<td>#Val_Action#</td>
<td>#Val_Orig#</td>
<td>#Val_New#</td>
</tr>
</cfoutput>
</cfloop>
</table>
</cfif>
</cfif>
<cfelse>
<cfoutput>form.#GridName#.#ColName#: NotSet!</cfoutput><br>
</cfif>
</cfloop>
Using the href attributeWhen specifying a URL with grid items using the href attribute, the selectMode attribute value determines whether the appended key value is limited to one grid item or extends to a grid column or row. When a user clicks a linked grid item, a cfgridkey variable is appended to the URL, in this form: http://myserver.com?cfgridkey=selection If the appendKey attribute is set to no, no grid values are appended to the URL. The value of selection is determined by the value of the selectMode and attribute:
When you use an href attribute, you can also specify a target attribute with any of the standard HTML target specifiers, _blank, _parent, _self, and _top, or with a specific frame name. ExampleThe following example creates a Flash form that displays a set of available courses from the CourseList table in the cfdocexamples database. For more complex examples that use the cfgrid tag, see cfgridcolumn, cfgridrow, and cfgridupdate. <!--- Query the database to fill up the grid. --->
<cfquery name = "GetCourses" dataSource = "cfdocexamples">
SELECT Course_ID, Dept_ID, CorNumber,
CorName, CorLevel
FROM CourseList
ORDER by Dept_ID ASC, CorNumber ASC
</cfquery>
<h3>cfgrid Example</h3>
<i>Currently available courses</i>
<!--- cfgrid must be inside a cfform tag. --->
<cfform>
<cfgrid name = "FirstGrid" format="Flash"
height="320" width="580"
font="Tahoma" fontsize="12"
query = "GetCourses">
</cfgrid>
</cfform>
|