Blog

Luis Majano

December 10, 2009

Spread the word


Share your thoughts


Let's learn how to use the paging carrousel plugin for ColdBox found in the ForgeBox directory.  First of all, download the plugin and drop in your custom plugins folder.


Settings setup

Make sure that you setup the following settings in your application:

PagingMaxRows - The maximum number of rows to show per page. Defaults to 10
PagingBandGap - The gap to use in the paging carrousel. Defaults to 5

You can also override the settings on the plugin, by using the appropriate setter methods in the plugin.

Handler setup

In your handler event, my case 'forgeservice.entries' you will setup the paging boundaries and the data call using these boundaries.  In my case, I have a model object that received the starting row and the maximum number of rows to return.  The paging plugin assumes there will be an incoming request collection variables called "page".  You do not need to param it or default it as the plugin does this for you.  All you have to do is construct a nice link with a page holder once you render the paging carrousel.  So to start just get the boundaries from the plugin:

// Get the paging boundaries, make sure there will be a "page" incoming variable, we use it to page.
rc.pageBoundaries = getMyPlugin("Paging").getBoundaries();

The previous call returns a structure with a startRow and maxRow element according to your settings and the page your are on.  You can use this information to present information back to the user like, showing records X to Y, etc.

// Call your model object for data
rc.entries = forgeService.getEntries(orderBy=rc.orderBy,
                                                            typeSlug=rc.typeSlug,
                                                            startrow=rc.pageBoundaries.startRow,
                                                            maxrows=getMyPlugin("Paging").getPagingMaxRows());     
      

The next tricky part is to get the total count with no paging on it.  I have another method that does this for me, but this can be done in any approach you prefer.

// Get total entries count
rc.entriesTotal = forgeService.getEntriesTotal(typeSlug=rc.typeSlug);

View Setup
That's it for the handler code, now let's render the paging carrousel.  For this make sure you have the correct css setup for it.  The following are what is needed for the paging css:

.pagingTabs - The div container
.pagingTabsTotals - The totals
.pagingTabsCarrousel - The carrousel

Here is my sample css: /* Paging */ .pagingTabs{ font-size: .8em; text-align: left; margin: 20px 10px 15px 10px; } .pagingTabs a{ color: #000; padding: 2px 4px; background-color: #fff; border: 1px solid #ccc; margin-left: 2px; } .pagingTabs a:hover{ color: #000; background-color: #FCF9C3; border: 1px solid black; } .pagingTabs a.selected{ color: #000; background-color: #FCF9C3; border: 1px solid #AF3D15; } .pagingTabsCarrousel{ margin-top:5px; }


Now I can render it in my views:


#getMyPlugin("paging").renderit(foundRows=rc.entriesTotal,link=event.buildLink('forgebox/page/@page@')#


That's it! I tell the paging plugin what is the link to attach to my carrousel and then pass a placeholder variable for my page: @page@.  This renders the carrousel and correct links.


Add Your Comment

(6)

Dec 10, 2009 01:58:52 UTC

by doug boude

Luis, in your example, does @page@ mean that if I use that in the buildlink method, CB will look for an rc variable named the same and replace the placeholder with the value?

Dec 10, 2009 02:02:59 UTC

by Luis Majano

Hi Doug, the plugin looks for the @page@ placeholder and replaces it with the correct page value. All this is inside the custom plugin. You can use buildLink() and it will leave your @page@ intact. The custom plugin is the one that translates it

Jan 20, 2011 10:50:15 UTC

by Alexandra

How can I download the plug in, I don't see a link!!!

Jan 20, 2011 12:09:44 UTC

by Luis Majano

The first link: http://www.coldbox.org/forgebox/view/RecordPaging

Jun 17, 2011 02:59:30 UTC

by West

What would I need to modify to have two paging widgets on the same page? Thanks

Jun 17, 2011 11:06:12 UTC

by Luis majano

Render two times you mean? Just call the render it method again

Recent Entries

Hackers demand a ransom to restore data from my ColdFusion web applications!

Hackers demand a ransom to restore data from my ColdFusion web applications!

Hackers demand a ransom to restore data from my ColdFusion web applications!

Unfortunately, we often hear this message from clients who thought it would never happen to them... until it did. Some believed they could delay the expense of Implementing ColdFusion security best practices for one year, while others were tempted to put it off for just a few months. However, in today's rapidly evolving digital landscape, the security of web applications, including ColdFusio...

Cristobal Escobar
Cristobal Escobar
April 16, 2024
Ortus March Newsletter

Ortus March Newsletter

Welcome to Ortus Solutions’ monthly roundup, where we're thrilled to showcase cutting-edge advancements, product updates, and exciting events! Join us as we delve into the latest innovations shaping the future of technology.

Maria Jose Herrera
Maria Jose Herrera
April 01, 2024
Into the Box 2024 Last Early Bird Days!

Into the Box 2024 Last Early Bird Days!

Time is ticking, with less than 60 days remaining until the excitement of Into the Box 2024 unfolds! Don't let this golden opportunity slip away; our exclusive Early Bird Pricing is here for a limited time only, available until March 31st. Why wait? Secure your seat now and take advantage of this steal!

Maria Jose Herrera
Maria Jose Herrera
March 20, 2024