2 Replies Latest reply on Jan 23, 2007 1:33 PM by Newsgroup_User

    Alt row color in grouped output

      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...
        • 1. Re: Alt row color in grouped output
          beenawhile Level 1
          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)
          @ #coldfusion / DALnet
          • 2. Re: Alt row color in grouped output
            Level 7
            <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'))#">
            <!--- whatever you do here --->
            <cfset myCounter = myCounter + 1>