Coldfusion MX PageList's Ashes version _coldfusion

Source: Internet
Author: User
Tags prev
You want the function is here, attention is pagelist, this is one of the CCF core code, I believe that the code is less than the pagelist less. There is absolutely no discount on the function. including PageList home/Last page, up/down page, page number can set display number, This avoids the number of a lot of up to pull pagelist long ....
Define the following variables in the source file that calls PageList:
<cfset Rowsperpage=10> <!---the number of records displayed per page----->
<cfparam name= "Url.startrow" default= "1" type= "Numeric" >
<cfset totalrows=newarticle. Recordcount>
<cfset endrow=min (url.startrow+rowsperpage-1,totalrows) >
<cfset startrownext=endrow+1>
<cfset startrowback=url.startrow-rowsperpage>


PageList code: You can keep it as a Web page, and then insert it into the place you want to display. Change the name of the query variable to your own query variable name.


<cfsetting enablecfoutputonly= "Yes" ><!---compressed white space to improve performance--->
<cfparam name= "page" default=1 type= "Numeric" > <!---Initialize page number--->
<cfparam name= "n" default=7 type= "Numeric" > <!---settings 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 (newarticle.recordcount/rowsperpage) >
<cfset min = Min-(max-ceiling (newarticle.recordcount/rowsperpage)) >
<cfset max = Ceiling (newarticle.recordcount/rowsperpage) >
</cfif>

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

<!--home first-->
<cfif page Neq 1>
<cfoutput>
<a href= "#CGI. script_name#? Startrow=1&page=1 "title=" Home "><<</a>
</cfoutput>
</cfif>

<!--pages PageList-->
<cfloop index= "x" from= "#min #" to= "#max #" >
<cfset nextpage=x*rowsperpage-(rowsperpage-1) >
<cfoutput>
<cfif page eq x>[#x #] <cfelseif nextpage LTE newarticle.recordcount>
<a href= "#CGI. script_name#? startrow= #nextpage #&page= #x # "> #x #</a>
</cfif>
</cfoutput>
</cfloop>

<!--last-->
<cfset laststartrow=newarticle.recordcount-rowsperpage+1>
<cfif page Neq max>
<cfoutput>
<a href= "#CGI. script_name#? startrow= #laststartrow #&page= #Ceiling (newarticle.recordcount/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 # "> Prev </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 compression blank feature--->


Code Copy Box
The following is a reference fragment:

<cfsetting enablecfoutputonly= "Yes" ><!---compressed white space to improve performance--->
<cfparam name= "page" default=1 type= "Numeric" > <!---Initialize page number--->
<cfparam name= "n" default=7 type= "Numeric" > <!---settings 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 (newarticle.recordcount/rowsperpage) >
<cfset min = Min-(max-ceiling (newarticle.recordcount/rowsperpage)) >
<cfset max = Ceiling (newarticle.recordcount/rowsperpage) >
</cfif>

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

<!--home first-->
<cfif page Neq 1>
<cfoutput>
<a href= "#CGI. script_name#? Startrow=1&page=1 "title=" Home "><<</a>
</cfoutput>
</cfif>

<!--pages PageList-->
<cfloop index= "x" from= "#min #" to= "#max #" >
<cfset nextpage=x*rowsperpage-(rowsperpage-1) >
<cfoutput>
<cfif page eq x>[#x #] <cfelseif nextpage LTE newarticle.recordcount>
<a href= "#CGI. script_name#? startrow= #nextpage #&page= #x # "> #x #</a>
</cfif>
</cfoutput>
</cfloop>

<!--last-->
<cfset laststartrow=newarticle.recordcount-rowsperpage+1>
<cfif page Neq max>
<cfoutput>
<a href= "#CGI. script_name#? startrow= #laststartrow #&page= #Ceiling (newarticle.recordcount/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 # "> Prev </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 compression blank feature--->




GAME over.
Explain some of the control statements that are not commented on above:
<cfparam name= "n" default=7 type= "Numeric" >
This setting defaults to 7, which means that when you browse the 12 records, you will see 9 10 11 [12] 13 14 15
Count, is not 7, this is an important part, you can also set to even, but the effect is not how good, unbalanced.
In addition, there is the function of automatic hiding. For example, I am on the last page, not the last and next page.

Again, you have to replace the name of your own query variable with newarticle.recordcount, the variable name I set. It is best to replace it all at once with find/replace.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.