I have a report-like view that outputs data, most ...
# cfml-general
d
I have a report-like view that outputs data, most commonly grouped by some specific column. In that common case, the outer output tag is roughly <cfoutput query="#q#" group="someColumn"> and the inner one has no group attribute. Suppose there's a new flavor that doesn't group at all, just lists the records in some order. Far as I can see, that needs different code to do the rendering, since there's no way to say group="" or anything like that, and in any case, you'd need to only have one level of output tag, not two. So I need different output code, yes?
t
You might be able to combine them by using an
attributeColletion
struct. Rather than specifying each attribute separately, you can specify them in a struct, and then pass that to the tag as
<cftag attributeCollection="#someStruct#">
So then you've have like
Copy code
outputAttributes = { query: q };
if( groupExists() ) {
    outputAttributes.group = "someColumn";
}

<cfoutput attributeCollection="#outputAttributes#">
If there's nothing to group by, then it excludes the group attribute entirely.
d
I wondered about that, but cfdocs didn't mention that cfoutput took an attributeCollection. But I see ACF does document it, so cool, thanks!
t
yeah, i think that all tags have attributeCollection.
d
Noted. I've been around too long, back from when that wasn't true 🙂
w
if that doesn't work for you you can always fall back to the oldskool/poor man's way of cfoutputting with grouping, it's just a little more code
also, you can just group on the primary key column in the absence of any other grouping col, that'll be equivalent to not having a grouping in the cfoutput
would probably choose the latter
d
Well kinda. In the group version, the outer cfouput tag has only a header with (more or less) just the value of the group field, and the inner one has "all the columns". If the outer one doesn't group at all, "all the columns" would need to be at that outer level, and the inner tag would need to not exist. Or am I thinking about this wrong?
w
sounds like what i refer to as poor man's grouping:
Copy code
<cfset groupColumn = false>
<cfset lastGroup = "">
<cfoutput query="q">	
	<cfif groupColumn and lastGroup neq q.parentGroup>
		<h3>#q.parentGroup#</h3>
		<cfset lastGroup = q.parentGroup>
	</cfif>
	id: #id#, name: #name#<br>
</cfoutput>
simply changing the groupColumn boolean should allow both to use the same cfoutput
d
Yeah, the Fred Flintstone version. (Just to note, he's a good friend of mine, much respect 🙂 ). I was just wondering if there was a more idiomatic construct for it, seems not.