cfgrid
Description
Used 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.
Categories
Related
cfajaximport cfapplet cfcalendar cfform cfformgroup cfformitem cfgridcolumn cfgridrow cfgridupdate cfinput cfselect cfslider cftextarea cftree
History
ColdFusion
9:
Added collapsible, groupfield,
and title attributes, supported in HTML grids only.
Added ability to use the insert attribute in HTML grids.
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:
Added the format attribute
and support for Flash and XML output.
Added enabled, onChange, style, tooltip,
and visible attributes (Flash format only).
ColdFusion
MX: Changed the rowHeaderWidth attribute: ColdFusion
does not use the rowHeaderWidth attribute. You
can omit it.
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.
Attributes
| Attribute | Description | Required | Default |
|---|---|---|---|
| align | Alignment of the grid cell contents: Top Left Bottom Baseline Texttop Absbottom Middle Absmiddle Right | Optional; applet | |
| appendKey | yes: when used with href, appends "CFGRIDKEY=" and information about the selected items. For details, see the section Using the href attribute. no | Optional; HTML, applet | yes |
| autoWidth | yes: sets column widths so that all columns display within the grid width. Widths are equal or the proportions are determined by the relative cfgridcolumnwidth attribute values. Horizontal scroll bars are not available. no: sets columns to equal widths or the values specified in the cfgridcolumnwidth attributes. | Optional; HTML, applet | no |
| bgColor | Background color of the control. For most formats, can be a hexa-decimal format or a named color. For a hexadecimal value, use the form "##xxxxxx", where x = 0-9 or A-F; use two number signs or none. For a list of the supported named colors, see cfchart. Limitations: for HTML format, must be a valid web color; for Flash format, must be a hexadecimal value. Flash format only: to specify background colors for alternating rows, separate the two colors with a comma. | Optional; all | |
| bind | A bind expression used to fill the contents of the grid. Cannot be used with the query attribute. For more information, see Binding data to form fields in Using Ajax Data and Development Features in the Developing ColdFusion Applications. | Optional; HTML | |
| bindOnLoad | yes: executes the bind attribute expression when first loading the form. no: does not execute the bind attribute expression until the first bound event. Ignored if there is no bind attribute. For more information, see Using the bindOnLoad attribute in the Developing ColdFusion Applications. | Optional; HTML | yes |
| bold | yes: displays text in bold. no | Optional; all | no |
| colHeaderAlign | left: left-aligns the column header text. right: right-aligns the column header text. center: centers the column header text. | Optional; applet | left |
| colHeaderBold | yes: displays column headers in bold. no | Optional; all | no |
| colHeaderFont | Font of column header. | Optional; all | |
| colHeaderFontSize | Size of column header text, in points. | Optional; all | |
| colHeaderItalic | yes: displays column headers in italic. no | Optional; all | no |
| colHeaders | yes: displays column headers. no | Optional; Applet, Flash | yes |
| colHeaderTextColor | Color of column headers. Options: same as for textColor attribute. | Optional; all | |
| collapsible | A Boolean value specifying whether the user can collapse the entire grid by clicking an arrow on the title bar. Specifying this attribute adds a title bar to the grid. | Optional; HTML | False |
| delete | yes: users can delete row data from the grid; takes effect only if selectmode="edit". no | Optional; HTML, applet | no |
| deleteButton | Text for the Delete button; takes effect only if selectmode="edit". | Optional; HTML, applet | Delete |
| enabled | Flash format only: Boolean value that specifies whether the control is enabled. A disabled control appears in light gray. | Optional; Flash | yes |
| font | Font of text. | Optional; all | |
| fontSize | Size of text, in points. | Optional; all | |
| format | applet: generates a Java applet. Flash: generates a Flash grid control. html: generates an AJAX-based HTML grid control that supports data binding. xml: generates an XML representation of the grid. In XML format forms, includes the generated XML in the form. In HTML format forms, puts the XML in a string variable with the name specified by the name attribute. | Optional; all | applet |
| gridDataAlign | left: left-aligns data within the column. right: right-aligns data within the column. center: centers data within the column. | Optional; applet | left |
| gridLines | yes: enables row and column rules. no | Optional; applet, Flash | yes |
| groupField | Puts the grid rows into groups, organized by the column specified in this attribute. Each group is collapsible and has a header with the column name, group field value, and number of entries in the group. If you set this option, the column pull-down menu shows two grouping options: The show in Groups option turns column grouping on and off. The Group By This Field option sets the grouping to use the selected column. Users display the pull-down menu by moving the mouse over a column head and clicking the down arrow that appears You can use this attribute with static grids only, do not use it with dynamic grids that get their data using bind expressions. | Optional; HTML | Don’t group |
| height | Height of the control, in pixels. If you omit the attribute in Flash format, the grid sizes automatically. | Optional; all | 300 (applet only) |
| highlightHref | yes: highlights links associated with an href attribute value. no | Optional; applet | yes |
| href | URL or name of a query column that contains URLs to hyperlink each grid cell with. | Optional; HTML,. applet | |
| hrefKey | A query column to use for the value appended to the href URL of each cell, if appendKey="True". If you use cfgridcolumn tags, the column must be specified in one of these tags. | Optional; HTML,. applet | |
| hSpace | Horizontal space to the left and right of the control, in pixels. | Optional; applet | |
| insert | yes: users can insert row data in the grid; takes effect only if selectmode="edit". no | Optional; applet, html | no |
| insertButton | Text for the Insert button; takes effect only if selectmode="edit". | Optional; applet | Insert |
| italic | yes: displays text in italic. no | Optional; all | no |
| maxRows | Maximum number of rows to display in the grid. | Optional; all | |
| name | Name of the grid control. | Required; all | |
| notSupported | Text to display if the browser does not support Java or has Java support disabled. Default: "<b> Browser must support Java to view ColdFusion Java Applets</b>" | Optional; applet | See Description |
| onBlur | ActionScript that runs when the grid loses focus. | Optional, Flash | |
| onChange | Flash format: ActionScript to run when the control changes due to user action in the control. HTML format: Required for HTML format grids that specify a bind attribute and a selectMode value of edit. A bind expression that calls a CFC method, JavaScript function, or URL to update the data source. If a URL is called, since the data is passed in JSON format to the URL page, use the function DeserializeJSON. The arguments cfgridrow and cfgridchanged must be serialized to JSON strings if a JavaScript bind is used to pass these arguments to a URL. | Optional; HTML, Flash | |
| onError | In HTML format grids, name of a JavaScript function to execute if an error occurs. In applet format grids, name of a JavaScript function to execute if validation fails. | Optional; HTML, applet | |
| onFocus | ActionScript that runs when the grid gets focus. | Optional, Flash | |
| onLoad | A custom JavaScript function to execute when the grid is loaded and rendered. | Optional | |
| onValidate | A JavaScript function to validate user input. The form object, input object, and input object value are passed to the function, which must return true if validation succeeds; false otherwise. | Optional; applet | |
| pageSize | The number of rows to display per page for a dynamic grid. If the number of available rows exceeds the page size, the grid displays only the specified number of entries on a single page, and the user navigates between pages to show all data. The grid retrieves data for each page only when it is required for display. This attribute is ignored if you specify a query attribute. | Optional; HTML | 10 |
| pictureBar | yes: puts images (and no text) on the Insert, Delete, and Sort buttons. no: puts text (and no images) on the Insert, Delete, and Sort buttons. | Optional; applet | no |
| preservePageOnSort | Specifies whether to display the page with the current page number, or display page 1, after sorting (or resorting) the grid. If this attribute is yes, selections are preserved when the grid sorts. | Optional; HTML | no |
| query | Name of the query associated with the control. Cannot be used with the bind attribute. | Optional; all | |
| rowHeaderAlign | left: left-aligns the row header text. right: right-aligns the row header text. center: centers the row header text. | Optional; applet | left |
| rowHeaderBold | yes: displays row label text in bold. no | Optional; applet | no |
| rowHeaderFont | Font for the row labels. | Optional; applet | |
| rowHeaderFontSize | Text size of the row labels, in points. | Optional; applet | |
| rowHeaderItalic | yes: displays row label text in italic. no | Optional; applet | no |
| rowHeaders | yes: displays a column of numeric row labels. no | Optional; applet | yes |
| rowHeaderTextColor | Text color of grid control row headers. Options: same as for the textColor attribute. | Optional; applet | black |
| rowHeight | Minimum row height, in pixels. Used with cfgridcolumntype="Image"; defines space for graphics to display in row. | Optional; Applet, Flash, XML | |
| selectColor | Background color for a selected item. Options: same as for textColor attribute | Optional; all | |
| selectMode | Selection mode for items in the control. Edit: the user can edit grid data. Selecting a cell lets the user edit the cell. Row: user selections automatically extend to the row that contains selected cell. The following are used in applet format only; HTML and Flash formats interpret these as Row: Single: user selections are limited to the selected cell. Column: user selections automatically extend to the column that contains selected cell. Browse: the user can only browse grid data. | Optional; all | Applet format: Browse; HTML, Flash format: Row |
| selectOnLoad | yes: selects the first row of the grid when the gird loads. no: does not select any rows when the grid loads. | Optional; HTML | yes |
| sort | Adds sort buttons to perform simple text sorts on a user-selected column: yes: put sort buttons on the grid control. no Independent of this setting, users can sort columns by clicking the column head. If selectMode="browse", the table cannot be sorted. | Optional; applet | no |
| sortAscendingButton | Text for the Sort button. | Optional; applet | A > Z |
| sortDescendingButton | Text for the Sort button. | Optional; applet | Z > A |
| stripeRowColor | The color to use for one of the alternating stripes. The bgColor setting determines the other color. | Optional; HTML | |
| stripeRows | Boolean value that indicates whether to make the rows stripes in alternating colors. | Optional; HTML | no |
| style | Must be a style specification in CSS format. Ignored for type="text". | Optional; Flash | |
| target | The target frame or window in which to display the href URL; for example, "_blank". | Optional; HTML, applet | |
| textColor | Color of text. Can be a hexadecimal value or a named color. For a hexadecimal value, use the form "##xxxxxx", where x = 0-9 or A-F; use two number signs or none. For a list of the supported named colors, see cfchart. | Optional Flash, applet | |
| title | Text to display as a title at the top of the grid. Specifying this attribute adds a title bar to the grid. | Optional; HTML | |
| tooltip | Flash format only: text to display when the mouse pointer hovers over the control. | Optional; Flash | |
| visible | Flash format only: Boolean value that specifies whether to show the control. Space that would be occupied by an invisible control is blank. | Optional; Flash | yes |
| vSpace | Vertical space above and below the control, in pixels. | Optional; applet | |
| width | Width of the control. In Flash and applet format, must be a number of pixels. In HTML format, can be in any valid CSS measurement unit, and a numeric-only value specifies pixels. If you omit the attribute in Flash or HTML format; the grid sizes automatically. | Optional; all | 300 (applet only) |
Usage
Most 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:
A column for each column in the query.
A default header for each column, created by replacing hyphen or underscore characters in the table column name with spaces. The first character, and any character after a space, are changed to uppercase; all other characters are lowercase.
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.
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:
A column for each column in the query.
A default header for each column, created by replacing hyphen or underscore characters in the table column name with spaces. The first character, and any character after a space, are changed to uppercase; all other characters are lowercase.
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.
Example
The
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>