cf_MagicPager: Coldfusion custom tag

cf_Magicpager is a Coldfusion custom tag that enables pagination. Pagination allows a website's users to navigate through a large record set in a user friendly way by generating page numbered links to each page in the archive. See example here

Download the tag and docs here

The very latest version can be obtained from it's svn repository.
https://svn2.hosted-projects.com/stewy/myApps/cf_magic_pager/

  • Previous and next links are also displayed to allow user to go back and forward one page at a time.
  • The pageNumber currently being viewed is highlighted a different color from the other pageNumbers.

The tag does not retrive and display records from a database .This is left up the developer to do in a seperate process. Giving flexibility as to what and how you display your records. In this respect the tag is very much an UI tag.An example of how records could be retrived and displayed is included in the code example in the docs.

The tag is designed to be linked to the displayed records using a variable called url.pageNumber. Each time a generated page number/link is clicked a variable called url.pageNumber is set with the page number.(Its defaults to one) Use this variable to help determine what records from your recordset (archive) should queryed and displayed on each page. E.G. If the number of the page currently being processed is 7 then you should seperately retrive and display records 70 to 79 from your recordset/archive.

Possible Tag Usage:
Place tag above or/and below where the records are output on template.

<!---CFC which generates your record set/ archive --->
<cfinvoke component="archive" method="getArchive" returnvariable="result">

<!---Calling magicPager to appear above record set --->

<cf_magicPager NumberOfPages="#result.numberOfPages#" NumberOfLinksOnPage="#result.NumberOfLinksOnPage#">
</cf_magicPager>


<!---Output your records here --->
<cfoutput query="result.records">
<p>
#title#<br>
#intro#<br>
<a href="fullArticle.cfm?articleId=#articleId#">Read more...</a><br>
</p>
</cfoutput>

<!---Calling magicPager to appear below record set --->
<cf_magicPager NumberOfPages="#result.numberOfPages#" NumberOfLinksOnPage="#result.NumberOfLinksOnPage#">
</cf_magicPager>

Attributes: (all are required) These values are best calculated alongside whatever code you use to retrive your database records. A cfc would be best, returning a structure that contains your database records and these values.

  • NumberOfPages: The number of pages you want your archive to have.This can be determined by dividing the record count value of a retrived record set by the number of records/articles you want to appear on any one page. e.g. 300 records retrived / 10 records on a page: this will give a figure of 30 pages. This is the amount of pages that will be needed to display the whole archive/record set.With each individual page being generated when a user clicks on its page number.
  • NumberOfPageLinks: The amount of page links to display on screen at any one time. This figure is doubled by the tag. e.g. If you enter 10 it will generate 20 links. 10 links before current page number, (if current page number is greater than 10) and 10 links after current page number (until there are less than 10 pages left to display in archive)

Comments
Jyoti's Gravatar Thank you Paul for putting this custom tag out there. The tag works like wonders. After
doing a Google search for the pagination logic in CF, this was most
easiest to use, that goes well with SQL Server as the database, and
has all the pages and Previous and Next buttons. Instructions and
example are very clear to understand.
# Posted By Jyoti | 5/27/08 9:12 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.002. Contact Blog Owner