6

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

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

编辑:你也可以称之为无限滚动表

4

4 回答 4

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() {
  }
}
于 2010-10-25T19:27:12.200 回答
1

Dean 已经提到了 Ext GWT,但我也想推荐SmartGWT 的实现

于 2010-07-15T14:44:47.323 回答
0

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

于 2010-07-08T11:30:55.760 回答
0

对的,这是可能的。这里曾经有一个名为 DynaGrid 的示例,但该链接现在已失效。我无法在其他任何地方找到它(注意:这与SourceForge 上的 DynaGrid 不同)。您或许可以联系作者 Reinier Zwitserloot,询问有关获取他的 DynaGrid 副本的问题。您也可以搜索GWT Group,如果没有找到任何内容,请在此处发帖询问是否有其他人知道在哪里可以找到它。

于 2010-06-28T14:31:43.737 回答