GWT 2.1数据表示小部件没有分页

时间:2010-06-27 22:18:57

标签: gwt tabular

我正在尝试构建一个包含大型数据集的表,并希望避免分页。 (我想做一些类似于Yahoo Mail网格的东西,它在绘制网格后检索数据。我认为最初检索前100封邮件,然后只有在用户向下滚动后才检索邮件)

我见过的数据表示小部件的例子包括分页。可以做我想做的事吗?

编辑:您也可以将其称为无限滚动表

4 个答案:

答案 0 :(得分:4)

GWT Showcase

中有一个例子
/**
 * A scrolling pager that automatically increases the range every time the
 * scroll bar reaches the bottom.
 */
public class ShowMorePagerPanel extends AbstractPager {

  /**
   * The default increment size.
   */
  private static final int DEFAULT_INCREMENT = 20;

  /**
   * The increment size.
   */
  private int incrementSize = DEFAULT_INCREMENT;

  /**
   * The last scroll position.
   */
  private int lastScrollPos = 0;

  /**
   * The scrollable panel.
   */
  private final ScrollPanel scrollable = new ScrollPanel();

  /**
   * Construct a new {@link ShowMorePagerPanel}.
   */
  public ShowMorePagerPanel() {
    initWidget(scrollable);

    // Handle scroll events.
    scrollable.addScrollHandler(new ScrollHandler() {
      public void onScroll(ScrollEvent event) {
        // If scrolling up, ignore the event.
        int oldScrollPos = lastScrollPos;
        lastScrollPos = scrollable.getScrollPosition();
        if (oldScrollPos >= lastScrollPos) {
          return;
        }

        HasRows display = getDisplay();
        if (display == null) {
          return;
        }
        int maxScrollTop = scrollable.getWidget().getOffsetHeight()
            - scrollable.getOffsetHeight();
        if (lastScrollPos >= maxScrollTop) {
          // We are near the end, so increase the page size.
          int newPageSize = Math.min(
              display.getVisibleRange().getLength() + incrementSize,
              display.getRowCount());
          display.setVisibleRange(0, newPageSize);
        }
      }
    });
  }

  /**
   * Get the number of rows by which the range is increased when the scrollbar
   * reaches the bottom.
   *
   * @return the increment size
   */
  public int getIncrementSize() {
    return incrementSize;
  }

  @Override
  public void setDisplay(HasRows display) {
    assert display instanceof Widget : "display must extend Widget";
    scrollable.setWidget((Widget) display);
    super.setDisplay(display);
  }

  /**
   * Set the number of rows by which the range is increased when the scrollbar
   * reaches the bottom.
   *
   * @param incrementSize the incremental number of rows
   */
  public void setIncrementSize(int incrementSize) {
    this.incrementSize = incrementSize;
  }

  @Override
  protected void onRangeOrRowCountChanged() {
  }
}

答案 1 :(得分:1)

Dean已经提到了Ext GWT,但我也建议SmartGWT's implementation

答案 2 :(得分:0)

是的,有可能。曾经有一个名为DynaGrid here的例子,但这个链接现在已经死了。我无法在其他任何地方找到它(注意:这与DynaGrid on SourceForge不一样)。您或许可以联系作者Reinier Zwitserloot,询问是否可以获得他的DynaGrid副本。您也可以搜索GWT Group,如果找不到任何内容,请在那里发帖询问是否有其他人知道在哪里找到它。

答案 3 :(得分:0)

Ext Gwt(AKA GXT)有一个支持此功能的“Live Grid”实现(参见http://www.sencha.com/examples/explorer.html#livegrid)。代码是GPL,尽管您可以购买许可证以在商业应用程序中使用它。