GWT 2.1 Data Presentation Widgets without paging
I am trying to build a table with large dataset and would like t开发者_JS百科o avoid paging. (I would like to do something similar to Yahoo Mail grid which retrieves data after the grid is drawn. I think initially the first 100 mails are retrieved and then mail is only retrieved after the user scrolls down)
The example of the data presentation widget I have seen include paging. Is it possible to do what I want?
edit: You could also call this an infinite scroll table
There are an exemple of this in the 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() {
}
}
Dean already mentioned Ext GWT but I'd like to suggest SmartGWT's implementation as well.
Yes, it is possible. There used to be an example of that called DynaGrid here but that link is dead now. I haven't been able to find it anywhere else (note: that's not the same as the DynaGrid on SourceForge). You might be able to contact the author, Reinier Zwitserloot, to inquire about getting a copy of his DynaGrid. You could also search the GWT Group and if you don't find anything, post there asking if anyone else knows where to find it.
Ext Gwt (AKA GXT) has an implementation of a "Live Grid" that supports this functionality (see http://www.sencha.com/examples/explorer.html#livegrid). The code is GPL although you can buy a license to use this in commercial applications.
精彩评论