Java
  Home arrow Java arrow Page 2 - Creating a Dynamic Scrollbar for an AJAX-b...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Creating a Dynamic Scrollbar for an AJAX-based Pagination System
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 20
    2006-06-12

    Table of Contents:
  • Creating a Dynamic Scrollbar for an AJAX-based Pagination System
  • Implementing a realistic scroll bar: using a third-party JavaScript library
  • Fetching database records in the background: unleashing the power of AJAX
  • Assembling the pieces: listing the full client code of the pagination system

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Creating a Dynamic Scrollbar for an AJAX-based Pagination System - Implementing a realistic scroll bar: using a third-party JavaScript library


    (Page 2 of 4 )

    In order to construct an efficient dynamic scroll bar, which will be used for determining when to fetch chunks of database records according to its physical position, I'm going to use Michael Foster's X library. The main purpose of utilizing this powerful JavaScript package is simply to create a realistic "drag-and-drop" element (the scrollbar handle), without having to reinvent the wheel by coding a script from scratch.

    Since the X library requires the inclusion of three JavaScript files, that is "x_core.js", "x_event.js" and "x_drag.js" respectively, in order to create a dragging element, it is not surprising that I should start including these files on the web page, as shown below:

    <script type="text/javascript" src="path-to-library/x_core.js"></script>

    <script type="text/javascript" src="path-to-library /x_event.js"></script>

    <script type="text/javascript" src="path-to-library /x_drag.js"></script>

    Now, after importing the previous JavaScript files right into the web document, the next step rests on developing the corresponding functions that first initialize the handle of the scroll bar, and then define the behavior for each one of its possible states: when the dragging action is started, during the dragging process, and finally when this process has ended.

    That said, here are the JavaScript functions that implement the dragging effect on the dynamic scroll bar:

    // initialize 'controlbar' element and assign events
    function initControlBar(){
        var controlbar=xGetElementById('controlbar');
        if(!controlbar){return};
        xMoveTo(controlbar,700,68);
        xEnableDrag(controlbar,controlbarOnDragStart,controlbarOnDrag,
    controlbarOnDragEnd);
        xShow(controlbar);
    }

    // define 'controlbarOnDragStart()' function
    function controlbarOnDragStart(obj,mdx,mdy){
       obj.totalMY=!obj.totalMY?0:obj.totalMY;
    }

    // define 'controlbarOnDrag()' function
    function controlbarOnDrag(obj,mdx,mdy){
        obj.totalMY+=mdy;
        window.status=obj.totalMY;
        if(obj.totalMY>345){obj.totalMY=345;return};
        if(obj.totalMY<0){obj.totalMY=0;return};
        xMoveTo(obj,700,xTop(obj)+mdy);
    }

    // define 'controlbarOnDragEnd()' function
    function controlbarOnDragEnd(obj,mdx,mdy){
        // modify this divisor to scope all rows
        var newoffset=Math.round(obj.totalMY/80);
        if(newoffset!=offset){
            offset=newoffset;
            sendHttpRequest(newoffset);
        }
    }

    As you can see, the first function of the above listing, that is "initControlBar()," is responsible for assigning the different callback functions that will control the operation of the "controlbar" DIV element. As you learned in the previous article, this element is simply the handle of the dynamic scroll bar, and it must be configured to trigger HTTP requests at predefined offset intervals, to fetch packets of database records in the background.

    Aside from the respective "controlbarOnStartDrag()" and "controlbarOnDrag()" functions, undoubtedly the function that plays the most important role here is "controlbarOnDragEnd()." As you can appreciate by this function's source code, whenever the user releases the handle of the scroll bar (dragging has stopped), an HTTP request is made by calling the "sendHttpRequest()" function, resulting in the display of a new set of database records. Are you starting to see how the dynamic scroll bar will retrieve paginated data? I bet you do.

    So far, you hopefully understand the complete process of turning a simple DIV element into an entirely programmable dragging control, which is placed inside the corresponding dynamic scroll bar. Now, let's move on and have a look at the remaining JavaScript functions, which are responsible for creating XMLHttpRequest objects, as well as for triggering and checking HTTP requests.

    To learn how this will be achieved, please read the following section.

    More Java Articles
    More By Alejandro Gervasio


       · In this article, you'll see how all the JavaScript functions that integrate the AJAX...
       · This tutorial is exactly what I'm looking for. The author mentions a third part, but...
       · Hi Rodney,Thank you for commenting on my AJAX article. Now, the third tutorial...
       · Hello,In this article you mention something about the first tutorial, and I can't...
       · Thank you for posting your comments on my AJAX article. You can read the first part...
       · Thank you for answering my question. As I am a new to php, I will really appreciate...
       · thank you again for posting your comments. Concerning your request, here's the...
       · Hi, i just read the tutorial and i think it is great.i have been trying to create...
       · Thank you for commenting on my Ajax article. Regarding your question, there’s a...
       · I could not find handle.gif and scrollbar.gif. Can you please send me the link for...
       · Thanks for the comments on my article. You can download directly the images from the...
       · Can you please tell me what can i do instead of getData.php in case of JSP.I need...
       · I wana jsp code instead of you have written code in PHP (getData.php). can you plz...
       · Hi Nikunj Mulani,Thanks for commenting on my AJAX article. Unfortunately, I...
       · Thanking you friendIt is really good artical. fortunatly i make my own...
     

    JAVA ARTICLES

    - Deploying Multiple Java Applets as One
    - Deploying Java Applets
    - Understanding Deployment Frameworks
    - Database Programming in Java Using JDBC
    - Extension Interfaces and SAX
    - Entities, Handlers and SAX
    - Advanced SAX
    - Conversions and Java Print Streams
    - Formatters and Java Print Streams
    - Java Print Streams
    - Wildcards, Arrays, and Generics in Java
    - Wildcards and Generic Methods in Java
    - Finishing the Project: Java Web Development ...
    - Generics and Limitations in Java
    - Getting Started with Java Web Development in...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT