Coldfusion MX PageList ashes

Source: Internet
Author: User

All the functions you need are here. Note that PAGELIST is one of the core CCF code. I believe that PAGELIST is less than my code. the function is not compromised. including pagelist homepage/last page, Previous Page/next page, the page number can be set to display the number, which avoids the long pagelist pulling when the number is more than one ....
Define the following variables in the source file that calls PAGELIST:
<Cfset rowsperpage = 10> <! --- 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 the code as a web page and insert it to the place you want to display it. Modify the query variable name to your own query variable name.

<Cfsetting enablecfoutputonly = "Yes"> <! --- Compress blank space to improve performance --->
<Cfparam name = "page" default = 1 type = "numeric"> <! --- Initialize the page number on this page --->
<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 (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>

<! -- Homepage first -->
<Cfif page NEQ 1>
<Cfoutput>
<A href = "# CGI. SCRIPT_NAME #? StartRow = 1 & Page = 1 "title =" Homepage "> </a>
</Cfoutput>
</Cfif>

<! -- Page 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 # "> 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 disable the empty space compression function --->

Code copy box
The following is a reference clip:

<Cfsetting enablecfoutputonly = "Yes"> <! --- Compress blank space to improve performance --->
<Cfparam name = "page" default = 1 type = "numeric"> <! --- Initialize the page number on this page --->
<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 (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>

<! -- Homepage first -->
<Cfif page NEQ 1>
<Cfoutput>
<A href = "# CGI. SCRIPT_NAME #? StartRow = 1 & Page = 1 "title =" Homepage "> </a>
</Cfoutput>
</Cfif>

<! -- Page 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 # "> 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 disable the empty space compression function --->

Game over.
Note the following control statements that have not been commented out:
<Cfparam name = "n" default = 7 type = "numeric">
The default value is 7. That is, when you browse 12 records, the system displays 9 10 11 [12] 13 14 15.
Count, isn't it 7, this is an important part, you can also set it to double number, but the effect will not be good, not balanced.
In addition, the above function is automatically hidden. For example, if I am on the last page, the last page and next page will not appear.

Remind me again: you must replace your own query variable name with newarticle. recordcount, which is the variable name I set. You 'd better replace all with Search/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.