JavaScript DHTML/YUI Library/Paginator

Материал из Web эксперт
Перейти к: навигация, поиск

Configuring the 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.ru/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>Configuring the 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" />
<link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/datatable/assets/skins/sam/datatable.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>
<script type="text/javascript" src="yui_2.7.0b-lib/datasource/datasource-min.js"></script>
<script type="text/javascript" src="yui_2.7.0b-lib/datatable/datatable-min.js"></script>

<!--begin custom header content for this example-->
<style type="text/css">
#demo {
    width: 525px;
}
#pag {
    display: inline;
    float: left;
    width: 250px;
    margin-top: 0;
}
#pag a {
    color: #0000de;
}
#pag label {
    display: block;
    margin: 1ex 0;
}
#pag p {
    margin: .25ex 0;
}
.yui-skin-sam #pag .yui-pg-pages {
    display: block;
}
.yui-skin-sam #pag .yui-pg-page {
    display: block;
    background: transparent;
    border: none;
    padding: .5ex 0;
    white-space: normal;
}
.yui-skin-sam #pag .yui-pg-current-page {
    padding: .5ex 0;
    background-color: #ffe;
    font-style: italic;
}
.yui-skin-sam #pag .yui-pg-current {
    margin: 0;
    white-space: normal;
    font-weight: bold;
    font-size: 113%;
}
.yui-skin-sam #demo .yui-dt caption {
    margin: 0.2em 0 0;
    color: #e76300;
    font-weight: bold;
}
</style>
<!--end custom header content for this example-->
</head>
<body class=" yui-skin-sam">

<h1>Configuring the Paginator</h1>
<div class="exampleIntro">
  <p>In this example we"ll demonstrate the use of all of Paginator"s configuration options, including the options added by the bundled UI Components.  Most notably, we"ll use the <code>template</code> and <code>pageLabelBuilder</code> options to render the pagination controls in a custom layout with more descriptive page links.  All content in the left column is generated by the Paginator.</p>
      
</div>
<!--BEGIN SOURCE CODE FOR EXAMPLE  -->
<div id="demo">
    <div id="pag"></div>
    <div id="tbl"></div>
</div>
<script type="text/javascript" src="yui_2.7.0b-assets/paginator-assets/areacodes.js"></script>
<script type="text/javascript">
YAHOO.util.Event.onDOMReady(function () {
var Ex = YAHOO.namespace("example");
// Sort our data by state, then area code
Ex.data.areacodes.sort(function (a,b) {
    return YAHOO.util.Sort.rupare(a.state,b.state) ||
           YAHOO.util.Sort.rupare(a.areacode,b.areacode);
});
// Custom function we"ll use for the page links
Ex.buildPageLabel = function (recs) {
    var data  = Ex.data.areacodes,
        start = recs[0],
        end   = recs[1];
    // Nested function to find the smallest substring
    // to indicate how two strings differ
    var diffNames = function (a,b) {
        var aa = a.state.toLowerCase(),
            bb = b.state.toLowerCase();
        for (var i = 0, len = aa.length; i < len; ++i) {
            if (aa.charAt(i) !== bb.charAt(i)) {
                return a.state.substr(0,i+1);
            }
        }
        return a.state + " ("+a.areacode+")";
    };
    // Build label as "A - C" or "Abc - Def"
    var label = "";
    if (!start) {
        label = data[0].state.substr(0,2) + " - ";
    } else {
        label = diffNames(data[start], data[start-1]) + " - ";
    }
    if (data[end+1]) {
        label += diffNames(data[end], data[end+1]);
    } else {
        label += diffNames(data[end], data[start]);
    }
    return label;
};

// Paginator configurations
Ex.config = {
    // REQUIRED
    rowsPerPage : 20,
    // REQUIRED, but DataTable will default if not provided
    containers  : "pag",
    // If not provided, there is no last page or total pages.
    // DataTable will set this in the DataSource callback, so this is
    // redundant.
    totalRecords : Ex.data.areacodes.length,
    // page to activate at load
    initialPage : 3,
    // Class the element(s) that will contain the controls
    containerClass : "yui-pg-container", // default
    // Define the innerHTML of the container(s) using placeholders
    // to identify where the controls will be located
    template :
        "<h3>Now showing:</h3>" +
        "<p>{CurrentPageReport}</p>" +
        "<p class="pg-nav">" +
            "{FirstPageLink} {PreviousPageLink} " +
            "{NextPageLink} {LastPageLink}" +
        "</p>" +
        "<label>Page size: {RowsPerPageDropdown}</label>" +
        "<h3>Directory</h3>" +
        "{PageLinks}",
    // If there is less data than would display on one page, pagination
    // controls can be omitted by setting this to false.
    alwaysVisible : true, // default
    // Override setPage (et al) to immediately update internal values
    // and update the pagination controls in response to user actions.
    // Default is false; requests are delegated through the changeRequest
    // event subscriber.
    updateOnChange : false, // default
    // Options for FirstPageLink component
    firstPageLinkLabel : "&lt;&lt;",
    firstPageLinkClass : "yui-pg-first", // default
    // Options for LastPageLink component
    lastPageLinkLabel : "&gt;&gt;",
    lastPageLinkClass : "yui-pg-last", // default
    // Options for PreviousPageLink component
    previousPageLinkLabel : "&lt; previous",
    previousPageLinkClass : "yui-pg-previous", // default
    // Options for NextPageLink component
    nextPageLinkLabel : "next &gt;", // default
    nextPageLinkClass : "yui-pg-next", // default
    // Options for PageLinks component
    pageLinksContainerClass : "yui-pg-pages",        // default
    pageLinkClass           : "yui-pg-page",         // default
    currentPageClass        : "yui-pg-current-page", // default
    // Display a maximum of X page links.  Use
    // YAHOO.widget.Paginator.VALUE_UNLIMITED to show all page links
    pageLinks               : YAHOO.widget.Paginator.VALUE_UNLIMITED,
    // Create custom page link labels
    pageLabelBuilder        : function (page,paginator) {
        return Ex.buildPageLabel(paginator.getPageRecords(page));
    },
    // Options for RowsPerPageDropdown component
    rowsPerPageDropdownClass : "yui-pg-rpp-options", // default
    rowsPerPageOptions       : [
        { value : 20, text : "small" },
        { value : 40, text : "medium" },
        { value : 100, text : "large" }
    ],
    // Options for CurrentPageReport component
    pageReportClass : "yui-pg-current", // default
    // Provide a key:value map for use by the pageReportTemplate.
    // Unlikely this will need to be customized; see API docs for the
    // template keys made available by the default value generator
    pageReportValueGenerator : function (paginator) {
        var recs  = paginator.getPageRecords();
        return {
            start     : Ex.data.areacodes[recs[0]].state,
            end       : Ex.data.areacodes[recs[1]].state
        };
    },
    // How to render the notification of the Paginator"s current state
    pageReportTemplate : "{start} - {end}"
};
// Create the Paginator for our DataTable to use
Ex.paginator = new YAHOO.widget.Paginator(Ex.config);

// Normal DataTable configuration
Ex.tableCols = [ {key:"state",    label:"State", minWidth: 150},
                 {key:"areacode", label:"Code",  width: 30}];
Ex.dataSource = new YAHOO.util.DataSource(Ex.data.areacodes, {
    responseType   : YAHOO.util.DataSource.TYPE_JSARRAY,
    responseSchema : {
        fields : ["state","areacode"]
    }
});
// Pass the Paginator in the DataTable config
Ex.tableConfig = {
    paginator : Ex.paginator,
    caption   : "Area Codes by State"
};
Ex.dataTable = new YAHOO.widget.DataTable("tbl",
    Ex.tableCols, Ex.dataSource, Ex.tableConfig);
});
</script>
<!--END SOURCE CODE FOR EXAMPLE  -->
</body>
</html>
<!-- presentbright.corp.yahoo.ru uncompressed/chunked Thu Feb 19 10:53:18 PST 2009 -->


<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>


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.ru/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 priest�s 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. Jim�s hands were behind his back, and sometimes his fingers clasped and unclasped. Again he said, �Pa!� The child�s 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 word��There!� The father had respected this silence with perfect courtesy. Afterward his glance carefully followed the direction indicated by the child�s finger, but he could see nothing which explained to him. �I don�t 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 boy�s 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.ru uncompressed/chunked Thu Feb 19 10:53:17 PST 2009 -->


<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>


Manually rendering Paginator UI Components

 

<!--
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.ru/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>Manually rendering Paginator UI Components</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">
.yui-skin-sam .yui-pg-container { margin: 0; }
.yui-skin-sam .yui-pg-current   { margin-right: 15px; }
.yui-skin-sam .yui-pg-previous {
    float: left;
    padding: 3px 5px;
}
.yui-skin-sam .yui-pg-next {
    float: right;
    padding: 3px 5px;
}
.yui-skin-sam span.yui-pg-next,
.yui-skin-sam span.yui-pg-previous {
    display: none;
}
#tbl,
#report,
#paging {
    width: 400px;
    margin: 0 auto;
}
#report {
    color: #fff;
    background: #ccc;
    font-size: 200%;
    margin-bottom: 1em;
    text-align: right;
}
#demo table {
    border-collapse: collapse;
    color: #333;
    width: 100%;
}
#demo th {
    border-bottom: 4px solid #999;
    color: #444;
    font: normal 125%/100% Trebuchet MS, Arial, sans-serif;
    padding: 0 6px;
}
#demo tbody {
    background: #fff;
    border-left: 1px solid #ccc;
    border-right: 1px solid #ccc;
}
#demo tbody td {
    border-bottom: 1px solid #eee;
    padding: 5px;
}
#demo tfoot td {
    overflow: hidden;
}
</style>
<!--end custom header content for this example-->
</head>
<body class=" yui-skin-sam">

<h1>Manually rendering Paginator UI Components</h1>
<div class="exampleIntro">
  <p>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).</p>
<p>For this example, we"ll create a table from a data array and render a few controls into the generated <code>&lt;tfoot&gt;</code> using the Paginator"s <code>template</code>.  We"ll also subscribe to the Paginator"s <code>render</code> event with a callback that renders a CurrentPageReport UI Component into a <code>&lt;div&gt;</code> above the table.</p>
      
</div>
<!--BEGIN SOURCE CODE FOR EXAMPLE  -->
<div id="demo">
    <div id="report"></div>
    <div id="tbl"></div>
</div>
<script type="text/javascript" src="yui_2.7.0b-assets/paginator-assets/inventory.js"></script>
<script type="text/javascript">
YAHOO.util.Event.onDOMReady(function () {
var Ex = YAHOO.namespace("example"),
    d  = document;
/* Convenience functions for building the DOM structure */
Ex.DOM = {
    create : function (el,innerHTML) {
        el = el && el.nodeName ? el : d.createElement(el);
        if (el && innerHTML !== undefined) {
            el.innerHTML = innerHTML;
        }
        return el;
    },
    add : function (par, child, innerHTML) {
        par = par && YAHOO.util.Dom.get(par);
        if (par && par.appendChild) {
            child = Ex.DOM.create(child,innerHTML);
            if (child) {
                par.appendChild(child);
            }
        }
        return child;
    }
};
/* Table generation/maintenance API */
Ex.table = {
    table   : null,
    columns : ["Item","Quantity","Description"],
    pageSize: 5,
    data    : null,
    tbody   : [],
    tfoot   : null,
    load : function (data) {
        if (YAHOO.lang.isArray(data)) {
            this.data = data;
            this.tbody = [];
        }
        return this;
    },
    render : function (container) {
        if (!this.table) {
            container = (container && YAHOO.util.Dom.get(container)) || d.body;
            var thead, tbody, row, cell, i, len;
            this.table = Ex.DOM.create("table");
            thead = Ex.DOM.add(this.table,"thead");
            row   = Ex.DOM.add(thead,"tr");
            for (i=0,len=this.columns.length; i<len; ++i) {
                Ex.DOM.add(row,"th",this.columns[i]);
            }
            this.tfoot = Ex.DOM.add(this.table,"tfoot");
            cell = Ex.DOM.add(Ex.DOM.add(this.tfoot,"tr"),"td");
            cell.colSpan = this.columns.length;
            if (this.data) {
                this.showPage(1);
            } else {
                row  = Ex.DOM.create("tr");
                cell = Ex.DOM.add(row,"td","No Data");
                cell.colSpan = this.columns.length;
                Ex.DOM.add(Ex.DOM.add(this.table,"tbody"),row);
            }
            container.innerHTML = "";
            Ex.DOM.add(container,this.table);
        }
        return this;
    },
    showPage : function (page) {
        var cur, tbody, row, i, j, len, limit;
        if (this.table) {
            cur = this.table.getElementsByTagName("tbody")[0];
            if (YAHOO.lang.isNumber(page)) {
                tbody = this.tbody[page];
                if (!cur || cur !== tbody) {
                    if (!tbody) {
                        tbody = this.tbody[page] = Ex.DOM.create("tbody");
                        i = (page - 1) * this.pageSize;
                        limit  = Math.min(Ex.data.inventory.length,
                                          i + this.pageSize);
                        for (; i < limit; ++i) {
                            row = Ex.DOM.add(tbody,"tr");
                            for (j=0,len=this.columns.length; j<len; ++j) {
                                Ex.DOM.add(row,"td",
                                    this.data[i][this.columns[j]]);
                            }
                        }
                    }
                    if (cur) {
                        this.table.replaceChild(tbody,cur);
                    } else {
                        Ex.DOM.add(this.table,tbody);
                    }
                }
            }
        }
        return this;
    }
};
    
Ex.handlePagination = function (state) {
    Ex.table.showPage(state.page);
    Ex.paginator.setState(state);
};
Ex.paginator = new YAHOO.widget.Paginator({
    rowsPerPage  : Ex.table.pageSize,
    totalRecords : Ex.data.inventory.length,
    containers   : d.createElement("div"),
    template              : "{PreviousPageLink}{NextPageLink}",
    pageReportTemplate    : "Page {currentPage} of {totalPages}",
    previousPageLinkLabel : "previous",
    nextPageLinkLabel     : "next"
});
Ex.paginator.subscribe("changeRequest", Ex.handlePagination);
Ex.paginator.subscribe("render", function () {
    var pageReport, pageReportNode, report;
    report = YAHOO.util.Dom.get("report");
    // Instantiate the UI Component
    pageReport = new YAHOO.widget.Paginator.ui.CurrentPageReport(Ex.paginator);
    // render the UI Component, passing an arbitrary string (the ID of the
    // destination container by convention)
    pageReportNode = pageReport.render("report");
    // Append the generated node into the container
    report.appendChild(pageReportNode);
});

// Render the UI
Ex.table.load(Ex.data.inventory).render("tbl");
// Render the Paginator controls into the off DOM div passed as a container
// just to illustrate that it is possible to do so.
Ex.paginator.render();
// Add the Paginator"s configured container to the table"s tfoot.
Ex.DOM.add(Ex.table.tfoot.rows[0].cells[0],Ex.paginator.getContainerNodes()[0]);
});
</script>
<!--END SOURCE CODE FOR EXAMPLE  -->
</body>
</html>
<!-- presentbright.corp.yahoo.ru uncompressed/chunked Thu Feb 19 10:53:17 PST 2009 -->


<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>


Partially revealing previous and next items

 
<!--
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.ru/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>Carousel: Partially revealing previous and next items</title>
<link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/fonts/fonts.css"> 
<link type="text/css" rel="stylesheet" href="yui_2.7.0b-lib/carousel/assets/skins/sam/carousel.css">
<script src="yui_2.7.0b-lib/yahoo-dom-event/yahoo-dom-event.js"></script>
<script src="yui_2.7.0b-lib/element/element-min.js"></script>
<script src="yui_2.7.0b-lib/carousel/carousel-min.js"></script>
</head>
<body class="yui-skin-sam">
<h1>Partially revealing previous and next items</h1>
<p> This example showcases a simple yet powerful feature of the <a href="http://developer.yahoo.ru/yui/carousel/">YUI Carousel Control</a>.  In this example, the Carousel displays the previous and next
  elements partially, giving a sneak peak of the upcoming image to the user.
  The <code>revealAmount</code> configuration setting accepts the percentage of the
  width of an item to reveal. </p>
<!-- The Carousel container -->
<div id="container">
    <ol id="carousel">
        <li>
            <img src="http://farm1.static.flickr.ru/32/52955391_e7bed4c41f_m.jpg"
                 height="180" width="240">
        </li>
        <li>
            <img src="http://farm1.static.flickr.ru/28/52955478_0a35209bbb_m.jpg"
                 height="180" width="240">
        </li>
        <li>
            <img src="http://farm1.static.flickr.ru/26/52955086_df2cdece3d_m.jpg"
                 height="180" width="240">
        </li>
        <li>
            <img src="http://farm1.static.flickr.ru/24/52956234_809467624f_m.jpg"
                 height="180" width="240">
        </li>
        <li>
            <img src="http://farm1.static.flickr.ru/30/52954770_ef743b4afe_m.jpg"
                 height="180" width="240">
        </li>
        <li>
            <img src="http://farm1.static.flickr.ru/33/52953744_1c4a4ffaaf_m.jpg"
                 height="180" width="240">
        </li>
        <li>
            <img src="http://farm1.static.flickr.ru/26/52953668_33ea00edac_m.jpg"
                 height="180" width="240">
        </li>
        <li>
            <img src="http://farm1.static.flickr.ru/32/52953229_28f32b92a1_m.jpg"
                 height="180" width="240">
        </li>
        <li>
            <img src="http://farm1.static.flickr.ru/32/52953161_9e067407b2_m.jpg"
                 height="180" width="240">
        </li>
        <li>
            <img src="http://farm1.static.flickr.ru/32/52953399_047d25504b_m.jpg"
                 height="180" width="240">
        </li>
    </ol>
</div>
<script>
    (function () {
        var carousel;
                
        YAHOO.util.Event.onDOMReady(function (ev) {
            var carousel    = new YAHOO.widget.Carousel("container", {
                        revealAmount: 25
                });
                        
            carousel.render(); // get ready for rendering the widget
            carousel.show();   // display the widget
        });
    })();
</script>
</body>
</html>
<!-- presentbright.corp.yahoo.ru uncompressed/chunked Thu Feb 19 10:53:08 PST 2009 -->


<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>


Rendering controls into multiple containers

 
<!--
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.ru/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>Rendering controls into multiple containers</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">
/* override some skin styles */
.yui-skin-sam span.yui-pg-container {
    display: inline;
}
.yui-skin-sam .yui-pg-current {
    margin: 0;
}
.yui-skin-sam #demo .yui-pg-container a:link,
.yui-skin-sam #demo .yui-pg-container a:active,
.yui-skin-sam #demo .yui-pg-container a:visited,
.yui-skin-sam #demo .yui-pg-container a:hover,
.yui-skin-sam #demo .yui-pg-container span.yui-pg-previous,
.yui-skin-sam #demo .yui-pg-container span.yui-pg-next {
    background: #fde;
    color: #f3c;
    text-decoration: none;
    border: 3px solid #f9c;
    padding: 0 3px;
    font-size: 130%;
    font-weight: bold;
}
.yui-skin-sam #demo .yui-pg-container span.yui-pg-previous,
.yui-skin-sam #demo .yui-pg-container span.yui-pg-next {
    background: #eee;
    color: #a6a6a6;
    border: 3px double #ccc;
}
.yui-skin-sam #demo .yui-pg-container a:hover {
    background: #f9c;
    color: #fff;
}
/* demo specific styles */
#demo h2 {
    border: none;
    border-bottom: 1ex solid #aaa;
    color: #333;
    font-size: 1.5em;
    line-height: 65%;
    margin-top: 0;
}
#content {
    margin: 0 0 0 4em;
    padding-top: 1em;
}
#content li {
    color: #f6c;
    font: bold italic 200%/.5 Arial, sans-serif;
    padding: 1px 0;
    margin: 0;
}
#content li p {
    color: #555;
    font: normal 50% Arial, sans-serif;
    margin: 0;
    line-height: 2;
}
#p_container {
    text-align: center;
}
</style>
<!--end custom header content for this example-->
</head>
<body class=" yui-skin-sam">

<h1>Rendering controls into multiple containers</h1>
<div class="exampleIntro">
  <p>In this example, we will add pagination to an ordered list.  Some things to note:</p>
<ul>
    <li>Pagination controls are added in a <code>&lt;span&gt;</code> as well as in a <code>&lt;p&gt;</code>.</li>
    <li>All included pagination controls use inline elements, so the containers needn"t be block elements.</li>
    <li>A custom skin treatment has been applied.</li>
    <li>State changes made to the Paginator propagate to all controls in all containers.</li>
</ul>
      
</div>
<!--BEGIN SOURCE CODE FOR EXAMPLE  -->
<div id="demo">
    <h2>1987 US Billboard Top 40!</h2>
    <p>
        Random content with pagination controls embedded inline.
        Suspendisse vestibulum dignissim quam. Integer vel augue.
        Phasellus nulla purus, interdum ac, and here they are.
        <span id="span_container"></span>
        and now back to random content habitant morbi tristique
        senectus et netus et malesuada fames ac turpis egestas.
    </p>
    <ol id="content" start="1">
        <!-- the paginated content will go here -->
    </ol>
    <p id="p_container"></p>
</div>
<script type="text/javascript" src="yui_2.7.0b-assets/paginator-assets/top40.js"></script>
<script type="text/javascript">
YAHOO.util.Event.onDOMReady(function () {
// Place code in the YAHOO.example namespace
var Ex = YAHOO.namespace("example");
Ex.content = YAHOO.util.Dom.get("content");
Ex.handlePagination = function (state) {
    // Gather the content for the requested page
    var startIndex = state.recordOffset,
        recs = Ex.data.top40.slice(startIndex, startIndex + state.rowsPerPage);
    // Update the content UI
    Ex.content.start = startIndex + 1;
    Ex.content.innerHTML = "<li><p>"+recs.join("</p></li><li><p>")+"</p></li>";
    // Confirm state change with the Paginator
    Ex.paginator.setState(state);
};
Ex.paginator = new YAHOO.widget.Paginator({
    rowsPerPage : 10,
    totalRecords : Ex.data.top40.length,
    containers : ["span_container","p_container"],
    template : "{PreviousPageLink} {CurrentPageReport} {NextPageLink}",
    previousPageLinkLabel : "&lt;",
    nextPageLinkLabel : "&gt;",
    pageReportTemplate : "{startRecord} - {endRecord} of the Top {totalRecords}"
});

Ex.paginator.subscribe("changeRequest", Ex.handlePagination);
Ex.paginator.render();
Ex.handlePagination(Ex.paginator.getState());
});
</script>
<!--END SOURCE CODE FOR EXAMPLE  -->
</body>
</html>
<!-- presentbright.corp.yahoo.ru uncompressed/chunked Thu Feb 19 10:53:17 PST 2009 -->


<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>


Server-side Pagination and Sorting for Dynamic Data

 
<!--
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.ru/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.
-->

<head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Server-side Pagination and Sorting for Dynamic Data</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" />
<link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/datatable/assets/skins/sam/datatable.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/connection/connection-min.js"></script>
<script type="text/javascript" src="yui_2.7.0b-lib/json/json-min.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>
<script type="text/javascript" src="yui_2.7.0b-lib/datasource/datasource-min.js"></script>
<script type="text/javascript" src="yui_2.7.0b-lib/datatable/datatable-min.js"></script>
<!--there is no custom header content for this example-->
</head>
<body class=" yui-skin-sam">

<h1>Server-side Pagination and Sorting for Dynamic Data</h1>
<div class="exampleIntro">
  <p>This example enables server-side sorting and pagination for data that is
dynamic in nature.</p>
      
</div>
<!--BEGIN SOURCE CODE FOR EXAMPLE  -->
<div id="dynamicdata"></div>
<script type="text/javascript">
YAHOO.example.DynamicData = function() {
    // Column definitions
    var myColumnDefs = [ // sortable:true enables sorting
        {key:"id", label:"ID", sortable:true},
        {key:"name", label:"Name", sortable:true},
        {key:"date", label:"Date", sortable:true, formatter:"date"},
        {key:"price", label:"Price", sortable:true},
        {key:"number", label:"Number", sortable:true}
    ];
    // Custom parser
    var stringToDate = function(sData) {
        var array = sData.split("-");
        return new Date(array[1] + " " + array[0] + ", " + array[2]);
    };
    
    // DataSource instance
    var myDataSource = new YAHOO.util.DataSource("yui_2.7.0b-assets/datatable-assets/php/json_proxy.php?");
    myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
    myDataSource.responseSchema = {
        resultsList: "records",
        fields: [
            {key:"id", parser:"number"},
            {key:"name"},
            {key:"date", parser:stringToDate},
            {key:"price",parser:"number"},
            {key:"number",parser:"number"}
        ],
        metaFields: {
            totalRecords: "totalRecords" // Access to value in the server response
        }
    };
    
    // DataTable configuration
    var myConfigs = {
        initialRequest: "sort=id&dir=asc&startIndex=0&results=25", // Initial request for first page of data
        dynamicData: true, // Enables dynamic server-driven data
        sortedBy : {key:"id", dir:YAHOO.widget.DataTable.CLASS_ASC}, // Sets UI initial sort arrow
        paginator: new YAHOO.widget.Paginator({ rowsPerPage:25 }) // Enables pagination 
    };
    
    // DataTable instance
    var myDataTable = new YAHOO.widget.DataTable("dynamicdata", myColumnDefs, myDataSource, myConfigs);
    // Update totalRecords on the fly with value from server
    myDataTable.handleDataReturnPayload = function(oRequest, oResponse, oPayload) {
        oPayload.totalRecords = oResponse.meta.totalRecords;
        return oPayload;
    }
    
    return {
        ds: myDataSource,
        dt: myDataTable
    };
        
}();
</script>
<!--END SOURCE CODE FOR EXAMPLE  -->
</body>


<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>