CFLib.org – Common Function Library Project

RowColor(colorList, currentRow[, delimiter])

Last updated December 21, 2011

author

Al Everett

Version: 1 | Requires: CF5 | Library: UtilityLib

Description:
Returns color from list of colors based on row number sent. Useful for alternating row colors in a table, but is not limited to two colors. Also see EvenOddColor.

Return Values:
Returns a string.

Example:

<cfset colorList=("blue,##ff0000,white")>
<cfoutput>
<table>
<cfloop from="1" to="10" index="i">
<tr bgcolor="#RowColor(colorList,i,",")#">
<td>Row Number: #i#</td>
</tr>
</cfloop>
</table>
</cfoutput>

Parameters:

Name Description Required
colorList List of colors. Yes
currentRow Current row number. Yes
delimiter List delimiter for colorList. Defaults to a comma. No

Full UDF Source:

/**
 * Returns alternating color based on list of colors.
 * 
 * @param colorList      List of colors. (Required)
 * @param currentRow      Current row number. (Required)
 * @param delimiter      List delimiter for colorList. Defaults to a comma. (Optional)
 * @return Returns a string. 
 * @author Al Everett (everett.al@gmail.com) 
 * @version 1, December 21, 2011 
 */
function rowColor(colorList,currentRow) {
    var delimiter=",";
    var rowColor="";
    var colorIndex=1;

    if (ArrayLen(arguments) GT 2) delimiter = arguments[3];
    
    colorIndex=currentRow MOD ListLen(colorList,delimiter) + 1;
    
    rowColor=ListGetAt(colorList,colorIndex,delimiter);
    
    return rowColor;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson