Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Section
Column
width60%

This page will walk you through an example of adding the Infusion Pager to your application.

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.

Panel
borderColor#566b30
bgColor#D3E3C4
borderStyleoutset

VERSION: This tutorial is based on v1.3.1 of Infusion. If you are still using v1.3, try the 1.3 tutorial.

Tutorial: How to Use the Pager

Scenario

You're implementing a roster for a large school, and since there are thousands of students at this school, you want the list of students to be paged. This tutorial will show you how to use the Infusion Pager for this.

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

  • Setup: Download and install the Fluid Infusion library
  • Step 1: Prepare your markup
  • Step 2: Write the script, setting the options
  • Step 3: Add the script and styles to your HTML

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

Column
Panel
borderColor#566b30
bgColor#fff
titleBGColor#D3E3C4
titleOn This Page
borderStylesolid
Table of Contents
minLevel2
maxLevel5
Panel
borderColor#321137
bgColor#fff
titleBGColor#c1b7c3
titleSee Also
borderStylesolid
Include Page
Infusion13:Still Need Help panel
Infusion13:Still Need Help panel

...

Include Page
Infusion13:Tutorial Setup
Infusion13:Tutorial Setup

...

Step 1: Prepare your markup

The Pager component works with the raw data that you want paged and lays it out according to a template you provide in your mark-up.

...

  • This code uses the Fluid Skinning System (FSS) for some layout, in particular, the "fl-force-left" and "fl-container-flex" classes.
  • This code assumes you have a CSS file containing the various "demo-..." CSS classes for styling the markup.

Selectors

Next, you will need to let the Pager know which pieces of mark-up are to be used for what. This is accomplished though an id or class on an element. In particular, you'll need to identify

...

This should get us started.

...

Step 2: Write the script, setting the options

You'll need to create a file, say pagersetup.js, to contain your initialization script: the script you write to apply the Pager to your roster. Let's start with this:

...

The Pager supports a number of options that can be set to configure the behaviour of the component. The options argument to the creator function is a JavaScript object containing the various options, some of which may be objects themselves. Let's go over the options we'll need to set for our Pager (for detailed information about all supported options, see the Pager API page).

bodyRenderer

The bodyRenderer option allows you to specify and configure the subcomponent used to render the actual data. The default body renderer is the self-renderer, fluid.pager.selfRender. This renderer uses the Infusion Renderer to populate your template with your data. We only need to tell the body renderer where the root of your template is.

...

Section
Column
Code Block
javascript
javascript
var opts = {
    bodyRenderer: {
        type: "fluid.pager.selfRender",
        options: {
            selectors: {
                root: ".demo-pager-table-data"
            }
        }
    }
};
Column

For more information about the various options that can be set for the body renderer, see Pager API.

dataModel

The dataModel option contains the actual data that you want paged, in the form of a pure-date JavaScript object. The structure of the object can take any form: paths expressed in component trees and configuration are expressed relative to this model.

...

Section
Column
Code Block
javascript
javascript
var opts = {
    bodyRenderer: {...},
    pagerBar: {...},
    dataModel: {
        "entityPrefix": "membership",
        "membership_collection": [
            {
                "memberRole": "Instructor",
                "userDisplayName": "Joe I. Instructor",
                "userEmail": "joe@none.none",
                "userComment": "Needs improvement."
            },
            {
                "memberRole": "TA",
                "userDisplayName": "Mike A. Smith",
                "userEmail": "msmith@none.none",
                "userComment": " "
            },
            {
                "memberRole": "Student",
                "userDisplayName": "Jane Doe",
                "userEmail": "j.doe@none.none",
                "userComment": " "
            },
            ...
    }
};
Column
Panel
borderColor#566b30
bgColor#D3E3C4
borderStyleoutset

While this snippet shows the data model being defined directly in the code, it is more likely that the actual data will be loaded through some other call to the server, such as fluid.fetchResources.

dataOffset

Section
Column

The dataOffset option tells the pager where in the dataModel to look for the actual data. This option is not always necessary, depending on the format of dataModel. In our case, we need to specify it, as shown on the right.

Column
Code Block
javascript
javascript
var opts = {
    bodyRenderer: {...},
    pagerBar: {...},
    dataModel: {...},
    dataOffset: "membership_collection"
};

model

The model option contains the initial settings for the Pager model itself. This is different than the dataModel: model includes information such as the number of items which may be shown on the page, the sort order, the index of the current page, etc. The Pager includes defaults for these, but for our use case, we'll override one of the defaults: We'd like the initial number of items per page to be larger than the default of 10:

Section
Column
Code Block
javascript
javascript
var opts = {
    bodyRenderer: {...},
    pagerBar: {...},
    dataModel: {...},
    dataOffset: "membership_collection",
    model: {
        pageSize: 20
    }
};
Column

For information about all of the model values that can be customized through the options, see Pager API.

columnDefs

The columnDefs option defines the rules for extracting and presenting data from the data model into your columns. It is an array containing one entry for each column which is to be rendered in the table.

...

These options are the minimum you will need to set to use the rendered Pager.

...

Step 3: Add the script and styles to your HTML

You'll need to add your initialization script, along with the Fluid library and Pager style sheets, to you HTML file, as shown below::

...

But all of these individual JavaScript files are not necessary to make it work - the InfusionAll.js file has everything you need.

...

Other Customizations

Sortable Columns

The Pager provides the ability to sort the table's rows with respect to a column. This is accomplished very easily, by simply

...

Section
Column
Code Block
html
html
...
<table summary="Table of all students and teachers." xmlns:rsf="http://ponder.org.uk">
    <thead>
        <tr rsf:id="header:">
            <th class="demo-pager-head-members"><a rsf:id="user-link" href="#">Members</a></th>
            <th class="demo-pager-head-email"><a rsf:id="user-email" href="#">Email</a></th>
            <th class="demo-pager-head-role"><a rsf:id="user-role" href="#">Role</a></th>
            <th><span class="demo-pager-head-comments">Comments</span></th>
        </tr>
    </thead>
    <tbody>
    ...
Column

When we convert the header text to a link, we must assign the link the same rsf:id as we did for the data in the columns themselves. This ensures that when the header is used to sort the data, the correct column of data is used.

Range Annotation

Another feature the Pager offers is the ability to provide information about what range of data is associated with a given page. This is an annotation attached to each page link, displayed as a tooltip when a page link is hovered over and spoken aloud by screen readers when a page link receives keyboard focus.

...