Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Since <code>DataGrid</code> doesn't expose it's <code>ScrollPanel</code>, create an inner class that extends <code>DataGrid</code> and provides a reference to the <code>ScrollPanel</code>:</p> <pre class="lang-java prettyprint-override"><code>private static class MyDataGrid&lt;T&gt; extends DataGrid { public ScrollPanel getScrollPanel() { HeaderPanel header = (HeaderPanel) getWidget(); return (ScrollPanel) header.getContentWidget(); } } </code></pre> <p>Initialize the variables needed for this to work:</p> <pre class="lang-java prettyprint-override"><code>private MyDataGrid&lt;MyDataType&gt; myDataGrid; private int incrementSize = 20; private int lastScrollPos = 0; </code></pre> <p>In the constructor, create the grid:</p> <pre class="lang-java prettyprint-override"><code>myDataGrid = new MyDataGrid&lt;MyDataType&gt;(); </code></pre> <p>Then add a ScrollHandler, using the getScrollPanel() reference that was just created:</p> <pre class="lang-java prettyprint-override"><code>myDataGrid.getScrollPanel().addScrollHandler(new ScrollHandler(){ @Override public void onScroll(ScrollEvent event) { int oldScrollPos = lastScrollPos; lastScrollPos = myDataGrid.getScrollPanel().getVerticalScrollPosition(); // If scrolling up, ignore the event. if (oldScrollPos &gt;= lastScrollPos) { return; } //Height of grid contents (including outside the viewable area) - height of the scroll panel int maxScrollTop = myDataGrid.getScrollPanel().getWidget().getOffsetHeight() - myDataGrid.getScrollPanel().getOffsetHeight(); if(lastScrollPos &gt;= maxScrollTop) { myDataGrid.setVisibleRange(0,myDataGrid.getVisibleRange().getLength()+incrementSize); } } }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload