Skip to Content »

Tech Life of Recht » Scroll Loader in GWT

 Scroll Loader in GWT

  • August 17th, 2006
  • 10:04 pm

Pagination is a normal and popular method of splitting data across pages. However, a new method has emerged (I forgot where I read about it first). Instead of distributing data across several pages (which is pretty non-Ajax), you place a scrollpanel around the data and load data when the scrollbar reaches the bottom.
See an example here.

Implementing this is actually pretty easy, especially with Google Web Toolkit. I've created a custom widget called ScrollAutoLoader, which handles scroll events. When used, you can implement scroll loading like this:

CODE:
  1. public class Module implements EntryPoint {
  2.     private int count;
  3.     private ScrollAutoLoader loader;
  4.     public void onModuleLoad() {
  5.   final VerticalPanel panel = new VerticalPanel();
  6.  
  7.   loader = new ScrollAutoLoader(panel, new Loader() {
  8.       public void load(int offset, int limit) {
  9.     panel.add(new Label("Line " + ++count));
  10.  
  11.     loader.fill();
  12.       }
  13.   }, 5);
  14.  
  15.   loader.setHeight("300px");
  16.  
  17.   RootPanel.get().add(loader);
  18.   loader.fill();
  19.     }
  20. }

I've used the widget a couple of places, and it works pretty good. It might, however, be too slow if there are a lot of pages, as the browser tends to slow down when the inner panel becomes too large.

Want your say?

* Required fields. Your e-mail address will not be published on this site

You can use the following XHTML tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>