CFLib.org – Common Function Library Project

recordsInView(rowsPerPage, currentPage, recordCount)

Last updated January 20, 2009

author

Tony Felice

Version: 0 | Requires: CF5 | Library: StrLib

Description:
Creates easy pagination output ie: (now showing) 101 to 105 of 105 (records) sort of thing.

Return Values:
Returns a string.

Example:

<cfoutput>recordsInView(20,6,105) produces:<br /> #recordsInView(20,6,105)#</cfoutput>

Parameters:

Name Description Required
rowsPerPage Number of rows per page. Yes
currentPage Current page. Yes
recordCount Total number of rows. Yes

Full UDF Source:

/**
 * Creates an easy reccord pagination indicator.
 * 
 * @param rowsPerPage 	 Number of rows per page. (Required)
 * @param currentPage 	 Current page. (Required)
 * @param recordCount 	 Total number of rows. (Required)
 * @return Returns a string. 
 * @author Tony Felice (sites@breckcomm.com) 
 * @version 0, January 20, 2009 
 */
function recordsInView(rowsPerPage,currentPage,recordCount){
	var first = "";
	var last = "";
	var output = "";
	if(currentPage eq 1){
		first = 1;
	}else{
		first = rowsPerPage*(currentPage - 1)+1;
	}
	if(rowsPerPage - ((currentPage*rowsPerPage) - recordCount) gt rowsPerPage){
		last = currentPage*rowsPerPage;
	}else{
		last = recordCount;
	}		
	
	if(first lt last){
		output = first & " to " & last & " of " & recordCount;
	}else if (first eq recordCount){
		output = first & " of " & recordCount;
	}else if (first gt recordCount){
		output = recordCount & " of " & recordCount;
	}
	return output;
}
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