Skip to main content
Participant
January 23, 2007
解決済み

Alt row color in grouped output

  • January 23, 2007
  • 返信数 2.
  • 488 ビュー
I've always used the following code to alternate row colors in a table of CFOUTPUT:

<tr bgcolor="#IIf(query.currentRow Mod 2, DE('cfcfcf'), DE('eeeeee'))#">

However, when I use this code in a table with grouped output, I get unpredictable row colors. For example, the first two rows will be color1, the next two color2, then the next few rows will alternate like I want.

I'm attaching the code I'm currently working on.

Any ideas how to get the alt row colors to display properly? Thanks in advance...
このトピックへの返信は締め切られました。
解決に役立った回答 beenawhile
Sorry, my initial search to find the answer came up nill. When I searched again I found the answer which I'm pasting below. It worked great.

===========================================================================
when you use the GROUP attribute of CFOUTPUT, your data is no longer being output in the same order in which it was retrieved. the CURRENTROW variable is no longer in chronological order (you're displaying the first grouped element, then 1-n members of that group, then repeating).

you'd need to set an iterating variable.

<cfset myRowCountVar = 0 />
<cfoutput query="q_remnts_f3" group="req_Cat">
<cfset myRowCountVar = myRowCountVar + 1 />

(now use 'myRowCountVar' to key off of to determine the background color rather than currentrow)

charlie griefer (CJ)
http://charlie.griefer.com
@ #coldfusion / DALnet
=================================================================================

返信数 2

Inspiring
January 23, 2007
<tr bgcolor="#IIf(query.currentRow Mod 2, DE('cfcfcf'), DE('eeeeee'))#">

Create your own counter. CurrentRow will always be the current row of
the query no matter what group it maybe in. So create your own counter
and increment it in the loop that relates to the rows you want to color,
then use this variable in your iif() function.

<cfset myCounter = 1>
<cfoutput query="foo" group="bar">
<tr bgcolor="#IIF(myCounter Mod 2, DE('cfcfcf'), DE('eeeeee'))#">
<cfoutput>
<!--- whatever you do here --->
</cfoutput>
</tr>
<cfset myCounter = myCounter + 1>
</cfoutput>

beenawhile作成者解決!
Participant
January 23, 2007
Sorry, my initial search to find the answer came up nill. When I searched again I found the answer which I'm pasting below. It worked great.

===========================================================================
when you use the GROUP attribute of CFOUTPUT, your data is no longer being output in the same order in which it was retrieved. the CURRENTROW variable is no longer in chronological order (you're displaying the first grouped element, then 1-n members of that group, then repeating).

you'd need to set an iterating variable.

<cfset myRowCountVar = 0 />
<cfoutput query="q_remnts_f3" group="req_Cat">
<cfset myRowCountVar = myRowCountVar + 1 />

(now use 'myRowCountVar' to key off of to determine the background color rather than currentrow)

charlie griefer (CJ)
http://charlie.griefer.com
@ #coldfusion / DALnet
=================================================================================