The Dopefly Tech Blog

<< The Dopefly Tech Blog Main page

Free code: Pagination.cfc

posted under category: Free Code For You on October 10, 2007 at 1:00 am by MrNate

Last weekend I updated my family photos area. I have to do something to it every few months so my wife will keep using it.

In the process, I created a cfc for paging through a query. I saw something similar on cflib.org, but I was hoping for something a little more OO and a little more customizable for me to use on any number of other projects.

Some cool things about it is the customizable output and the caching when you call getRenderedHTML() so you can output it at the top and the bottom of the page without any performance hit.

Some room for improvement would be adding a few more convenience methods like getCurrentPageNumber() and the option to leave the <Previous link text up (but no link) when there is no previous page, that kind of thing. More suggestions are definitely welcome. Also I think the API will change somewhat to make it more discoverable, but I'm not sure how, yet.

I created it and licensed it this weekend without a release, then earlier this week, I realized I could use it in a project at work. I downloaded it and dropped it in, and it worked perfectly with nothing to change.

So, this is version 0.1 with a BSD license (free to do what you want with it but leave my © on it). Download Pagination.cfc here.

BTW, before there is any confusion, this is a one-use-only object, you create an instance of it when you need to output pagination and throw it away with the page. Do not put it in your application scope. Coldspring users, singleton=false.

Too old to comment!
On Apr 24, 2008 at 1:00 AM Mike (mighunter, by way of hotmail.com) said:
I got this link from a post on easycfm.com and love the look of your pagination.cfc. However, I can't get it to work for me. Here is the post: http://easycfm.com/forums/viewmessages.cfm?Forum=12&Topic=13447

Is there anyway you can take a look at it and tell me what I am doing wrong? Someone posted that maybe I need to add startrow and maxrow attributes to the Query but I can't find anywhere in the files what vairables you might have used for these. Thanks.

On Apr 25, 2008 at 1:00 AM Nathan Strutz (http://www.dopefly.com/) said:
Mike,
Check out the new project page here on dopefly: http://www.dopefly.com/projects/Pagination/
and the project page on RIAForge:
http://paginationcfc.riaforge.com/

We've got some very good documentation and possibly a new version since you downloaded your copy, so you may want to try to update your version (current version as of this comment is 1.0RC), then check the docs to make sure you're doing it right.

On Jul 8, 2010 at 1:00 AM Loryn (lwilliams from princetonol.com) said:
Nathan,
I love the pagination.cc but I die everytime I try to move to another page - somehow the query is not cached and the results are not found. Should I be rerunning the query for every page? I am using cf serach and wouldbe happy to send the code if you like..

On Jul 8, 2010 at 1:00 AM Nathan Strutz (http://www.dopefly.com/) said:
Loryn,
Pagination isnt trying to cache the query, if you want to cache it, you can either cache it yourself, like put it in a different, longer lived scope (session, for instance), or you could extend Pagination.cfc to cache how you see fit. I think you may actually be able to cache the Pagination object itself in something like the session scope, but it isn't really set up like that. In short, yes, it expects you to re-run the search every time. Maybe in version 2...
Too old to comment!