SoFunction
Updated on 2025-04-14

Coldfusion MX PageList's Ashes Edition

All the functions you want are here. Note that it is PAGELIST, which is one of the core CCF codes. I believe there are fewer PAGELIST than my code. There is absolutely no discount on the functions. Including pagelist Home/Last Page, Previous/Next Page, Page Number can set the number of displayed numbers, which avoids the number of pagelist being pulled long...
Define the following variables in the source file that calls PAGELIST:
<cfset rowsperpage=10> <!---The number of records displayed per page----->
<cfparam name="" default="1" type="numeric"> 
<cfset totalrows=> 
<cfset endrow=Min(+rowsperpage-1,totalrows)> 
<cfset startRowNext=endrow+1> 
<cfset startrowBack=-rowsperpage> 


Pagelist code: You can keep it as a web page and then insert it to the place you want to display. Just modify the query variable name inside to your own query variable name.


<cfsetting enablecfoutputonly="Yes"><!--- Compressing the blanks, improving performance -->
<cfparam name="page" default=1 type="numeric"> <!--- Initialize this page number -->
<cfparam name="n" default=7 type="numeric"> <!--- Set how many pages can be displayed --->

<cfset min = page-Int(n/2)> 
<cfset max = page+Int(n/2)> 

<cfif min LT 1> 
 <cfset max = max - (min-1)> 
 <cfset min = 1> 
</cfif> 

<cfif max GT Ceiling(/rowsPerPage)> 
 <cfset min = min - (max - Ceiling(/rowsPerPage))> 
 <cfset max = Ceiling(/rowsPerPage)>
</cfif> 

<cfif min lt 1>
<cfset min=1>
</cfif> 

<!-- Home page first-->
<cfif page NEQ 1>
<cfoutput>
<a href="#CGI.SCRIPT_NAME#?StartRow=1&Page=1" title="Home"><<</a>
</cfoutput>
</cfif> 

<!-- Number of pages PAGELIST -->
<cfloop index="x" from="#min#" to="#max#">
<cfset nextpage=x*rowsperpage-(rowsperpage-1)>
<cfoutput>
<cfif page eq x>[#x#] <cfelseif nextpage LTE >
<a href="#CGI.SCRIPT_NAME#?StartRow=#nextpage#&Page=#x#">#x#</a>
</cfif>
</cfoutput>
</cfloop> 

<!-- Last -->
<cfset laststartrow=-rowsPerPage+1>
<cfif page NEQ MAX>
<cfoutput>
<a href="#CGI.SCRIPT_NAME#?StartRow=#laststartrow#&Page=#Ceiling(/rowsPerPage)#">>></a>
</cfoutput>
</cfif> 

<!-- Previous page/Next page -->
<cfoutput>
<CFIF startrowBack GT 0>
<cfif page EQ 1>
<CFSET NTback=1>
<cfelse>
<cfset NTback=page-1>
</cfif>
<a href="#CGI.SCRIPT_NAME#?startrow=#startrowback#&page=#NTback#">Previous page</a>
</CFIF>
<CFIF startrownext LTE totalrows>
<cfset NTnext=page+1>
<a href="#CGI.SCRIPT_NAME#?startrow=#startrownext#&page=#NTnext#">Next page</a>
</CFIF>
</cfoutput>
<cfsetting enablecfoutputonly="no"><!--- Don't forget to turn off the compressed blank function --->


Code copy box
The following is a quoted snippet:

<cfsetting enablecfoutputonly="Yes"><!--- Compressing the blanks, improving performance -->
<cfparam name="page" default=1 type="numeric"> <!--- Initialize this page number -->
<cfparam name="n" default=7 type="numeric"> <!--- Set how many pages can be displayed --->

<cfset min = page-Int(n/2)> 
<cfset max = page+Int(n/2)> 

<cfif min LT 1> 
 <cfset max = max - (min-1)> 
 <cfset min = 1> 
</cfif> 

<cfif max GT Ceiling(/rowsPerPage)> 
 <cfset min = min - (max - Ceiling(/rowsPerPage))> 
 <cfset max = Ceiling(/rowsPerPage)>
</cfif> 

<cfif min lt 1>
<cfset min=1>
</cfif> 

<!-- Home page first-->
<cfif page NEQ 1>
<cfoutput>
<a href="#CGI.SCRIPT_NAME#?StartRow=1&Page=1" title="Home"><<</a>
</cfoutput>
</cfif> 

<!-- Number of pages PAGELIST -->
<cfloop index="x" from="#min#" to="#max#">
<cfset nextpage=x*rowsperpage-(rowsperpage-1)>
<cfoutput>
<cfif page eq x>[#x#] <cfelseif nextpage LTE >
<a href="#CGI.SCRIPT_NAME#?StartRow=#nextpage#&Page=#x#">#x#</a>
</cfif>
</cfoutput>
</cfloop> 

<!-- Last -->
<cfset laststartrow=-rowsPerPage+1>
<cfif page NEQ MAX>
<cfoutput>
<a href="#CGI.SCRIPT_NAME#?StartRow=#laststartrow#&Page=#Ceiling(/rowsPerPage)#">>></a>
</cfoutput>
</cfif> 

<!-- Previous page/Next page -->
<cfoutput>
<CFIF startrowBack GT 0>
<cfif page EQ 1>
<CFSET NTback=1>
<cfelse>
<cfset NTback=page-1>
</cfif>
<a href="#CGI.SCRIPT_NAME#?startrow=#startrowback#&page=#NTback#">Previous page</a>
</CFIF>
<CFIF startrownext LTE totalrows>
<cfset NTnext=page+1>
<a href="#CGI.SCRIPT_NAME#?startrow=#startrownext#&page=#NTnext#">Next page</a>
</CFIF>
</cfoutput>
<cfsetting enablecfoutputonly="no"><!--- Don't forget to turn off the compressed blank function --->

 


GAME OVER.
Let me explain the several control statements that are not commented above:
<cfparam name="n" default=7 type="numeric">
The default setting here is 7, that is, when you are browsing 12 records, 9 10 11 [12] 13 14 15 will be displayed
Count it, whether there are 7 items, this is an important part. You can also set it to even numbers, but the effect will not be very good and it is unbalanced.
In addition, there is also an automatic hidden function above. For example, if I am on the last page, the last page and the next page will not appear.

Let me remind you again: you must replace the variable name I set with your own query variable name. It is best to use search/replace and replace all at once.