Northern Division Governor Area 1 Governor District Southern Division Governor Area 10 Governor District Southern Division Governor Area 11 Governor District Southern Division Governor Area 12 Governor District Northern Division Governor Area 2 Governor District Northern Division Governor Area 3 Governor District Northern Division Governor Area 4 Governor District Metro Division Governor Area 5 Governor District Metro Division Governor Area 6 Governor District Metro Division Governor Area 7 Governor District Metro Division Governor Area 8 Governor District Metro Division Governor Area 9 Governor District
<cfquery name="display" datasource="ic"> select * from org </cfquery> <cftable query="display"> <cfcol width="30" header="BOSS" text="#Boss#"> <cfcol header="TITLE" text="#Title#"> <cfcol header="GRP" text="#Grp#"> </cftable>
You'd think it would be easy to simplify this by writing cfcol tags with cfloop from the display.ColumnList variable. However, it won't work. The CFTABLE tag is perhaps the most primitive tag in the ColdFusion inventory. It does not permit any other tag to be used within it. So, you have to use it in the fashion shown above.
<cfquery name="display" datasource="ic"> select * from org </cfquery> <cftable query="display" htmltable> <cfcol header="BOSS" text="#Boss#"> <cfcol header="TITLE" text="#Title#"> <cfcol header="GRP" text="#Grp#"> </cftable>
Did you see the htmltable attribute? That's all it takes.
You'd think it would be easy to pick the kind of table you want by using a variable in place of "htmltable" and fill in the variable or leave it blank. This technique works other places in ColdFusion but not here. Again, this primitive tag will not recognize variables used in this manner.
Why not wrap the beginning tag in a cfif and simply pick a version with or without this attribute? This doesn't work either; ColdFusion sees the closing tag but claims not to see the opening tag.
<cfparam name="url.mode" default="text"> <cfquery name="display" datasource="ic"> select * from org </cfquery> <cfif url.mode is "html"> <cftable query="display" htmltable> <cfcol header="BOSS" text="#Boss#"> <cfcol header="TITLE" text="#Title#"> <cfcol header="GRP" text="#Grp#"> </cftable> <cfelse> <cftable query="display"> <cfcol width="30" header="BOSS" text="#Boss#"> <cfcol header="TITLE" text="#Title#"> <cfcol header="GRP" text="#Grp#"> </cftable> </cfif>
Save this as table.cfm. Call it as table.cfm?mode=html to get a table made from HTML tags. If you call it as table.cfm with no parameters or some other parameter, it produces a report formatted with spaces, using a non-proportional font. View the source to see the difference under the hood. Test my claims regarding its incompatibility with variables and other tags.
If you use this tag to make an HTML table, it has other attributes you can specify to dress it up a bit. However, I think it's most exciting to use in creating plain text reports on the fly. =Marty=