Child pages
  • Pager Tutorial - Markup-driven

Documentation for a historical release of Infusion: 1.3
Please view the Infusion Documentation site for the latest documentation.
If you're looking for Fluid Project coordination, design, communication, etc, try the Fluid Project Wiki.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 9 Next »

This tutorial is incomplete at this time. Once it is finished, this warning will be removed.

This documentation refers to the latest trunk version of the Pager code.

This page will walk you through an example of adding the Fluid Pager component to an HTML file.

This tutorial assumes that:

  • you are already familiar with HTML, Javascript and CSS
  • you are familiar with what the Pager is and does
  • now you just want to know how to add it to your file.

For more general information about the Pager, see Pager. For technical API documentation, see Pager API.

Tutorial: How to Use the Pager

Scenario

You've created a database to keep track of your vast collection of CDs, and you're working on a web interface for it. You'd like to break up long listings of search results into shorter, more managable chunks. This tutorial will show you how to use the Fluid Pager for this.

There are four basic steps to adding the Pager to your application:

  • Step 0: Download and install the Fluid Infusion library
  • Step 1: Prepare your markup
  • Step 2: Write the script
  • Step 3: Add the script to your HTML
  • Step 4: Apply styles

The rest of this tutorial will explain each of these steps in detail.

On This Page
See Also
Still need help?

Join the fluid-talk mailing list and ask your questions there.


Step 0: Download and install the Fluid Infusion library

  1. Download a copy of the Fluid Infusion component library from:
  2. Unpack the zip file you just downloaded, and place the resulting folder somewhere convenient for your development purposes.
    The folder will have the release number in it's name (e.g. fluid-0.4/). The rest of this tutorial will use fluid-0.4 in its examples, but if you downloaded a different version, you'll have to adjust.

Step 1: Prepare your markup

Unlike many other Fluid Components, the current version of the Pager is entirely mark-up driven. This means that the Pager component itself doesn't create or provide any markup - you have to provide it yourself.

The Pager requires certain minimum markup from you:

  1. The entire pager must be contained within a container element.
  2. Within that container, there are one or two 'pager bar' elements, each containing:
    • any number of page links
    • optionally, a 'next' element and a 'previous' element

So, this might look something like this:

Note that the image on the left is just an example. You could just as easily have a simple markup and styles that look like this:

The point is that your markup has the required elements.

Let's assume that you're starting with HTML file that produces something like the image above (but simplified, so that this tutorial doesn't get too verbose):

<ul id="pager-top" class="pager-top">
    <li value="1" class="page-link"><a href="#">1</a></li>
    <li value="2" class="page-link"><a href="#">2</a></li>
    <li value="3" class="page-link"><a href="#">3</a></li>
    <li class="previous"><a href="#">&lt; previous</a></li>
    <li class="next"><a href="#">next &gt;</a></li>
</ul>
<table summary="student grades" id="students-page1">
  <thead>
    <tr>
        <td>Name</td>
        <td>User Id</td>
        <td>Points</td>
    </tr>
  </thead>
  <tbody>
    <tr>
        <td>Ahn, Jason</td>
        <td>15234314</td>
        <td><input type="text" value="87" /></td>
    </tr>
    <tr>
        <td>Akerman, Krista</td>
        <td>19206726</td>
        <td><input type="text" value="79" /></td>
    </tr>
    <tr>
        <td>Almeida, Elaine</td>
        <td>19286942</td>
        <td><input type="text" value="92" /></td>
    </tr>
  </tbody>
</table>
<ul id="pager-bottom" class="pager-bottom">
    <li value="1" class="page-link"><a href="#">1</a></li>
    <li value="2" class="page-link"><a href="#">2</a></li>
    <li value="3" class="page-link"><a href="#">3</a></li>
    <li class="previous"><a href="#">&lt; previous</a></li>
    <li class="next"><a href="#">next &gt;</a></li>
</ul>

The Pager component needs to know about the 'container' of your markup. We'll wrap a <div> around the whole thing, and give it a unique ID:

<div id="gradebook">
  <ul id="pager-top" class="pager-top">
      <li value="1" class="page-link"><a href="#">1</a></li>
      <li value="2" class="page-link"><a href="#">2</a></li>
  ...
</div>

We also need to identify the various parts to the Pager. We'll do this by attaching CSS class names that the Pager will recognize.

The Pager recognizes several classes:

  • pager-top for the container of the link bar above the content
  • pager-bottom for the container of the link bar below the content
  • page-link for any link inside a link bar
  • next for the 'next' link
  • previous for the 'previous' link

We'll consider the <ul> elements to be the containers for the top and bottom link bars, and the <li> elements themselves to be the links:

<div id="gradebook">
  <ul class="pager-top">
      <li class="page-link"><a href="#">1</a></li>
      <li class="page-link"><a href="#">2</a></li>
      <li class="page-link"><a href="#">3</a></li>
      <li class="previous"><a href="#">&lt; previous</a></li>
      <li class="next"><a href="#">next &gt;</a></li>
  </ul>
  ...
  <ul class="pager-bottom">
      <li class="page-link"><a href="#">1</a></li>
      <li class="page-link"><a href="#">2</a></li>
      <li class="page-link"><a href="#">3</a></li>
      <li class="previous"><a href="#">&lt; previous</a></li>
      <li class="next"><a href="#">next &gt;</a></li>
  </ul>
</div>

You may have noticed that we haven't touched the <table> elements between the top and bottom link bars. That's because the Pager honestly couldn't care what you've got in there. The Pager is only concerned with the link bars, and what happens when you click on those links. And in fact, the Pager doesn't really care what you do when the links are clicked - it simply tells you which link was activated and hands control over to you to act accordingly. More on that soon, but for now, we need to be able to know which link was activated. We'll do this by adding a 'value' to each numbered <li> element:

<div id="gradebook">
  <ul id="pager-top" class="pager-top">
      <li value="1" class="page-link"><a href="#">1</a></li>
      <li value="2" class="page-link"><a href="#">2</a></li>
      <li value="3" class="page-link"><a href="#">3</a></li>
      <li class="previous"><a href="#">&lt; previous</a></li>
      <li class="next"><a href="#">next &gt;</a></li>
  </ul>
  ...
  <ul id="pager-bottom" class="pager-bottom">
      <li value="1" class="page-link"><a href="#">1</a></li>
      <li value="2" class="page-link"><a href="#">2</a></li>
      <li value="3" class="page-link"><a href="#">3</a></li>
      <li class="previous"><a href="#">&lt; previous</a></li>
      <li class="next"><a href="#">next &gt;</a></li>
  </ul>
</div>

That's all - these are the only changes you need to make to your HTML.


Step 2: Write the script

You'll need to create a file, say filename, to contain your initialization script - the script you write to apply the Pager to your <stuff>.

In this file, write a function that <...>:

jQuery(document).ready(function () {
    initialization code here
});

<explain the function>

Important note

<any caveats about selectors, and the fact that any selector will do, not just the one in the example.>


Step 3: Add the script to your HTML

You'll need to add your initialization script, along with the Fluid library, to you HTML file. In the header of the file, link to the Javascript files with <script> tags:

<script type="text/javascript" src="Fluid-all.js"></script>
<script type="text/javascript" src="<filename>.js"></script>

That's it! That's all you need to do to add the <...> functionality to your document.

BUT: If you look at the file in a browser now, it doesn't look any different than it looked before - there's no way to tell that <...>. That's what the styles are for.


Step 4: Apply styles

There are a number of "interesting moments" that happen while <...>. These include, for example, <...>

Important note

The styles in the example below are just that: examples. You are free to create whatever styles you like <...>. The important thing to understand is

  • what the interesting moments are, and
  • what the names of the styles for those moments are

The diagram below shows what the minimum elements might look like. The diagram to the right shows what all of the optional elements might look like.

  • No labels