Getting started with Paginator : Paginator « YUI Library « JavaScript DHTML






Getting started with Paginator

 


<!--
Software License Agreement (BSD License)
Copyright (c) 2009, Yahoo! Inc.
All rights reserved.

Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, this list of conditions and the
      following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    * Neither the name of Yahoo! Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of Yahoo! Inc.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Sources of Intellectual Property Included in the YUI Library

YUI is issued by Yahoo! under the BSD license above. Below is a list of certain publicly available software that is the source of intellectual property in YUI, along with the licensing terms that pertain to thosesources of IP. This list is for informational purposes only and is not intended to represent an exhaustive list of third party contributions to the YUI.

    * Douglas Crockford's JSON parsing and stringifying methods: In the JSON Utility, Douglas Crockford's JSON parsing and stringifying methods are adapted from work published at JSON.org. The adapted work is in the public domain.
    * Robert Penner's animation-easing algorithms: In the Animation Utility, YUI makes use of Robert Penner's algorithms for easing.
    * Geoff Stearns's SWFObject: In the Charts Control and the Uploader versions through 2.7.0, YUI makes use of Geoff Stearns's SWFObject v1.5 for Flash Player detection and embedding. More information on SWFObject can be found here (http://blog.deconcept.com/swfobject/). SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License (http://www.opensource.org/licenses/mit-license.php).
    * Diego Perini's IEContentLoaded technique: The Event Utility employs a technique developed by Diego Perini and licensed under GPL. YUI's use of this technique is included under our BSD license with the author's permission.

-->

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>


    <meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Getting started with Paginator</title>

<style type="text/css">
/*margin and padding on body element
  can introduce errors in determining
  element position and are not recommended;
  we turn them off as a foundation for YUI
  CSS treatments. */
body {
  margin:0;
  padding:0;
}
</style>

<link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/fonts/fonts-min.css" />
<link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/paginator/assets/skins/sam/paginator.css" />
<script type="text/javascript" src="yui_2.7.0b-lib/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="yui_2.7.0b-lib/element/element-min.js"></script>
<script type="text/javascript" src="yui_2.7.0b-lib/paginator/paginator-min.js"></script>


<!--begin custom header content for this example-->
<style type="text/css">
#content {
    background: #fff;
    border: 1px solid #ccc;
    color: #000;
    font-family: Times New Roman, serif;
    padding: 1em 2em;
}

#content div {
    display: none;
}
#demo .page1 div.page1,
#demo .page2 div.page2,
#demo .page3 div.page3,
#demo .page4 div.page4,
#demo .page5 div.page5 {
    display: block;
}
</style>

<!--end custom header content for this example-->

</head>

<body class=" yui-skin-sam">


<h1>Getting started with Paginator</h1>

<div class="exampleIntro">
  <p>In this example we illustrate the basics of attaching a Paginator to your application.  We take a short story by Stephen Crane and divide it up into pages, then use Paginator to display the page navigation.</p>
      
</div>

<!--BEGIN SOURCE CODE FOR EXAMPLE  -->

<div id="demo">
    <h2 class="first">The Monster</h2>
    <p>By Stephen Crane</p>

    <div id="paging"></div>

    <div id="content" class="page1">
        <div class="page1">
            <p>Little Jim was, for the time, engine Number 36, and he was making the run between Syracuse and Rochester. He was fourteen minutes behind time, and the throttle was wide open. In consequence, when he swung around the curve at the flower-bed, a wheel of his cart destroyed a peony. Number 36 slowed down at once and looked guiltily at his father, who was mowing the lawn. The doctor had his back to this accident, and he continued to pace slowly to and fro, pushing the mower.</p>     
            <p>Jim dropped the tongue of the cart. He looked at his father and at the broken flower. Finally he went to the peony and tried to stand it on its pins, resuscitated, but the spine of it was hurt, and it would only hang limply from his hand. Jim could do no reparation. He looked again toward his father.</p>     
        </div>
        <div class="page2">
            <p>He went on to the lawn, very slowly, and kicking wretchedly at the turf. Presently his father came along with the whirring machine, while the sweet, new grass blades spun from the knives. In a low voice, Jim said, Pa!</p>     
            <p>The doctor was shaving this lawn as if it were a priests chin. All during the season he had worked at it in the coolness and peace of the evenings after supper. Even in the shadow of the cherry-trees the grass was strong and healthy. Jim raised his voice a trifle. Pa!</p>     
            <p>The doctor paused, and with the howl of the machine no longer occupying the sense, one could hear the robins in the cherry-trees arranging their affairs. Jims hands were behind his back, and sometimes his fingers clasped and unclasped. Again he said, Pa! The childs fresh and rosy lip was lowered.</p>     
        </div>
        <div class="page3">
            <p>The doctor stared down at his son, thrusting his head forward and frowning attentively. What is it, Jimmie?</p>     
            <p>Pa! repeated the child at length. Then he raised his finger and pointed at the flower-bed. There!</p>     
            <p>What? said the doctor, frowning more. What is it, Jim?</p>     
            <p>After a period of silence, during which the child may have undergone a severe mental tumult, he raised his finger and repeated his former wordThere! The father had respected this silence with perfect courtesy. Afterward his glance carefully followed the direction indicated by the childs finger, but he could see nothing which explained to him. I dont understand what you mean, Jimmie, he said.</p>     
        </div>
        <div class="page4">
            <p>It seemed that the importance of the whole thing had taken away the boys vocabulary. He could only reiterate, There!</p>     
            <p>The doctor mused upon the situation, but he could make nothing of it. At last he said, Come, show me.</p>     
            <p>Together they crossed the lawn toward the flower-bed. At some yards from the broken peony Jimmie began to lag. There! The word came almost breathlessly.</p>     
            <p>Where? said the doctor.</p>     
            <p>Jimmie kicked at the grass. There! he replied.</p>     
        </div>
        <div class="page5">
            <p>The doctor was obliged to go forward alone. After some trouble he found the subject of the incident, the broken flower. Turning then, he saw the child lurking at the rear and scanning his countenance.</p>     
            <p>The father reflected. After a time he said, Jimmie, come here. With an infinite modesty of demeanour the child came forward. Jimmie, how did this happen?</p>     
            <p>The child answered, Now&#8212;I was playin train&#8212;and&#8212;now&#8212;I runned over it.</p>
        </div>
    </div>
</div>
<script type="text/javascript">
YAHOO.util.Event.onDOMReady(function () {

// Set up the application under the YAHOO.example namespace
var Ex = YAHOO.namespace('example');

Ex.content    = YAHOO.util.Dom.get('content');

Ex.handlePagination = function (state) {
    // Show the appropriate content for the requested page
    Ex.content.className = 'page' + state.page;
    
    // Update the Paginator's state, confirming change
    Ex.paginator.setState(state);
};

// Create the Paginator widget and subscribe to its changeRequest event
Ex.paginator = new YAHOO.widget.Paginator({
    rowsPerPage : 1,
    totalRecords : Ex.content.getElementsByTagName('div').length,
    containers : 'paging'
});

Ex.paginator.subscribe('changeRequest', Ex.handlePagination);

// Render the Paginator into the configured container(s)
Ex.paginator.render();

});
</script>

<!--END SOURCE CODE FOR EXAMPLE  -->

</body>
</html>
<!-- presentbright.corp.yahoo.com uncompressed/chunked Thu Feb 19 10:53:17 PST 2009 -->

   
  








yui_2.7.0b.zip( 4,431 k)

Related examples in the same category

1.Manually rendering Paginator UI Components
2.Server-side Pagination and Sorting for Dynamic Data
3.Configuring the Paginator
4.Rendering controls into multiple containers
5.Partially revealing previous and next items