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;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson