
726
DEVELOPING
COLDFUSION 9 APPLICATIONS
Requesting and Presenting Information
Las
t
upda
te
d 8/5/2010
Reviewing the code
The following table describes the highlighted code and its function:
Grouping output from a query
In a query that you display using a
cftree
control, to organize your employees by department, separate column names
with commas in the
cftreeitemvalue
attribute.
Organize the tree based on ordered results of a query
1
Create a ColdFusion page named tree2.cfm with the following content:
<!--- CFQUERY with an ORDER BY clause. --->
<cfquery name="deptquery" datasource="cfdocexamples">
SELECT Dept_ID, FirstName || ' ' || LastName
AS FullName
FROM Employee
ORDER BY Dept_ID
</cfquery>
<!--- Build the tree control. --->
<cfform name="form1" action="submit.cfm">
<cftree name="tree1"
hscroll="No"
border="Yes"
height="350"
required="Yes">
<cftreeitem value="Dept_ID, FullName"
query="deptquery"
queryasroot="Dept_ID"
img="computer,folder,document"
imgopen="computer,folder"
expand="yes">
</cftree>
<br>
<br><input type="Submit" value="Submit">
</cfform>
Code
Description
<cftree name="tree1"
Creates a tree and names it tree1.
required="Yes"
Specifies that a user must select an item in the tree.
hscroll="No"
Does not allow horizontal scrolling.
<cftreeitem value="FullName" query="engquery"
Creates an item in the tree and puts the results of the query named engquery
in it. Because this tag uses a query, it puts one item on the tree per query
entry.
queryasroot="Yes"
Specifies the query name as the root level of the tree control.
img="folder,document"
Uses the folder and document images that ship with ColdFusion in the tree
structure.
When populating a cftree tag with data from a cfquery tag, you can specify
images or filenames for each level of the tree as a comma-separated list.