Having a few issues trying to get my paging solution a little sleaker. What i am trying to accomplish is making the page links display 5 links left and right of the currently viewed page link eg..
<< 5 6 7 8 9 [10] 11 12 13 14 15 >>
Blow is my current NEXTN function which i use: -
<!--- Next-N() method --->
<cffunction name="nextN"
displayname="Next-N Method"
hint="Returns a structure containing row (next/back/end/totalrows)"
access="public"
returntype="struct"
output="false">
<cfargument name="rowsPerPage" type="numeric" required="no" default="10">
<cfargument name="startRow" type="numeric" required="no" default="1">
<cfargument name="qryRecordCount" type="numeric" required="yes">
<cfargument name="cgiRequestMethod" type="string" required="yes">
<!--- Setup nextN structure --->
<cfset var nextN = structnew()>
<!--- Setup rowsPerPage Default --->
<cfset nextN.rowsPerPage = arguments.rowsPerPage>
<!--- What row to start at? Assume first by default --->
<cfset nextN.startRow = arguments.startRow>
<!--- If form is posted set start row to 1 --->
<cfif NOT CompareNoCase(arguments.cg
iRequestMe
thod,"post
")>
<cfset nextN.startRow = 1>
</cfif>
<!--- We know the total number of rows from query --->
<cfset nextN.totalRows = arguments.qryRecordCount>
<!--- Last row is 10 rows past the starting row, or total number of query rows, whichever is less --->
<cfset nextN.endRow = Min(nextN.startRow + nextN.rowsPerPage - 1, nextN.totalRows)>
<!--- Next button goes to 1 past current end row --->
<cfset nextN.startRowNext = nextN.endRow + 1>
<!--- Back button goes back N rows from start row --->
<cfset nextN.startRowBack = nextN.startRow - nextN.rowsPerPage>
<cfreturn nextN>
</cffunction>
Example of current page links: -
<!--- Pagination --->
<div class="pagination">
<cfoutput>
<!--- Simple "Page" counter, starting at first "Page" --->
<cfset ThisPage = 1>
Page
<!--- Back button --->
<cfif nextN.startRowBack GT 0>
<a href="#cgi.script_name#?st
artrow=#ne
xtN.startR
owBack#&or
derby=#url
.orderBy#&
order=#url
.order#&#v
ariables.u
rlString#"
title="Back #nextN.rowsPerPage# records" tabindex="7">
<span>«</span>
</a>
</cfif>
<!--- Loop thru row numbers, in increments of RowsPerPage --->
<cfloop from="1" to="#nextN.totalRows#" step="#nextN.rowsPerPage#"
index="pageRow">
<!--- Detect whether this "Page" currently being viewed --->
<cfset IsCurrentPage = (pageRow gte nextN.startRow) AND (pageRow lte nextN.endRow)>
<!--- If this "Page" is current page, show without link --->
<cfif IsCurrentPage>
<b>#thisPage#</b>
<cfelse>
<!--- Otherwise, show with link so user can go to page --->
<a href="#cgi.script_name#?st
artrow=#pa
geRow#&ord
erby=#url.
orderBy#&o
rder=#url.
order#&#va
riables.ur
lString#" tabindex="6">#thisPage#</a
>
</cfif>
<!--- Increment ThisPage variable --->
<cfset thisPage = thisPage + 1>
</cfloop>
<!--- Next button --->
<cfif nextN.startRowNext LTE nextN.totalRows>
<a href="#cgi.script_name#?st
artrow=#ne
xtN.startR
owNext#&or
derby=#url
.orderBy#&
order=#url
.order#&#v
ariables.u
rlString#"
title="Next #nextN.rowsPerPage# records" tabindex="8">
<span>»</span>
</a>
</cfif>
</cfoutput>
</div>
Thanks
Jonathan
Start Free Trial