YUI Library Home

YUI Library Examples: Paginator: Manually rendering Paginator UI Components

Paginator: Manually rendering Paginator UI Components

If you have a UI where it doesn't make sense to place all controls in a single container (or set of containers), you can place individual UI Components manually outside Paginator's configured container(s).

For this example, we'll create a table from a data array and render a few controls into the generated <tfoot> using the Paginator's template. We'll also subscribe to the Paginator's render event with a callback that renders a CurrentPageReport UI Component into a <div> above the table.

Example Data

In this example, we'll be working with a data array stored in YAHOO.example.data.inventory.

Start with the content

We'll start with two empty divs:

To populate div#tbl we write some application code to generate a table with a tfoot. The table will be wrapped in an object with an API including a showPage(pageNumber) method.

Add Pagination

Create a Paginator and a method to subscribe to its changeRequest event. Note the configured container is a generated <div> and is not yet on the page. We'll append this to the <tfoot> when it is available.

Subscribe to create the CurrentPageReport

To synchronize the rendering of all UI Components, we subscribe to the Paginator's render event with a callback to add a CurrentPageReport into div#report.

UI Components' render methods take a string seed usually used by Paginator to guarantee uniqueness of generated IDs when rendering into multiple containers. When rendering them manually, you'll need to provide your own seed. If you render more than one of the same type of UI Component, respective render calls must be passed different seeds.

Render everything

Render the table and the Paginator. The CurrentPageReport will be rendered in response to the Paginator's emitted render event.

The Paginator was configured to use a <div> created off the page DOM, so the template controls are not visible until the <div> is then added to the table's <tfoot>.

Full Code Listing


Some convenience methods were created to aid in the DOM structure assembly.


Custom positioning and style were added to the UI Components used. You'll see the Sam skin overrides as the rules with selectors beginning with .yui-skin-sam.

Configuration for This Example

You can load the necessary JavaScript and CSS for this example from Yahoo's servers. Click here to load the YUI Dependency Configurator with all of this example's dependencies preconfigured.

Copyright © 2011 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings