• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Alt row color in grouped output

Community Beginner ,
Jan 23, 2007 Jan 23, 2007

Copy link to clipboard

Copied

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...
TOPICS
Advanced techniques

Views

385

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Jan 23, 2007 Jan 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).
...

Votes

Translate

Translate
Community Beginner ,
Jan 23, 2007 Jan 23, 2007

Copy link to clipboard

Copied

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
=================================================================================

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 23, 2007 Jan 23, 2007

Copy link to clipboard

Copied

LATEST
<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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation