ScrollPanel.scrollToBottom has no effect

325 views
Skip to first unread message

Magnus

unread,
Aug 16, 2012, 1:15:03 AM8/16/12
to google-we...@googlegroups.com
Hello,

I have a CellTable within a ScrollPanel with a fixed number of rows (40). Whenever the CellTable is filled with data by an AsyncDataProvider, the ScrollPanel should scroll down to the end of the CellTable.

So I call scrollToBottom at the end of the load process triggered by onRangeChanged, i. e. within onRangeChangend a RPC call is made to fetch the new data, and on response to this call the data is pushed into the CellTable and scrollToBottom is called (see below).

However, the scrolling does not work. I tried to trace it with a Window.alert call, and I believe that the CellTable with the new data is not yet displayed when scrollToBottom is called.

What can I do?

Any hints are welcome!

Thank you
Magnus



// AsyncDataProvider:

protected void onRangeChanged(HasData<MyData> display)
{
 Range r = display.getVisibleRange();
 int start = r.getStart() + 1;
 int end = start + r.getLength() - 1;
 loadData (start,end);
}

protected void loadData(int start,int end)
{
 AsyncCallback<List<MyData>> cbk = new AsyncCallback<List<MyData>>()
 {
  public void onFailure (Throwable thr) { }

  public void onSuccess (List<MyData> lst)
  {
    loadData (lst);
  }
 };

 dataService.loadData (start,end,cbk);
}

protected void loadData (List<MyData> lst)
{
 Range r = pager.getDisplay().getVisibleRange();
 int start = r.getStart();

 dataProvider.updateRowData (start,lst);
 
 Window.alert("scroll to bottom");
 scp.scrollToBottom();
}

















Paul Robinson

unread,
Aug 16, 2012, 1:55:04 AM8/16/12
to google-we...@googlegroups.com
Try calling scrollToBottom after the event loop has finished by running it inside a call to Scheduler.get().scheduleDeferred(...)

Paul
> --
> You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/oGv5jvVSM3cJ.
> To post to this group, send email to google-we...@googlegroups.com.
> To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Magnus

unread,
Aug 16, 2012, 11:27:10 PM8/16/12
to google-we...@googlegroups.com
Hello Paul,

this works fine! Thank you very much!!!

When I first saw your posting, I thought, that this would produce an unwanted flicker effect, because the list would first be drawn and then be scrolled. But this doesn't seem to be the case. I wonder, why? Does GWT "wait" with redrawing until all scheduled procedures have been processed?

However, scrolling down would not be needed if I were able to tell, how much rows of the CellTable fit in the visible area. But I think this cannot be done, can it?

Thanks again,
Magnus

Paul Robinson

unread,
Aug 17, 2012, 3:29:22 AM8/17/12
to google-we...@googlegroups.com
One of the nice things about SuperDevMode in chrome is that as you step through it in the chrome debugger, you can see exactly what the browser does and when because the browser display updates as you step through your code. In other words, if you want to know what's actually happening, you can use SuperDevMode and step through it.

You should be able to work out how many rows are visible after you've rendered it by getting the element for each row and finding its Y position compared to the Y position of the scroller. Look at com.allen_sauer.gwt.dnd.client.util.WidgetArea for clues as to how to do this (this is a part of gwt-dnd here: http://code.google.com/p/gwt-dnd/)

Paul
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.

adanz...@gmail.com

unread,
Jun 12, 2013, 5:36:21 PM6/12/13
to google-we...@googlegroups.com
Hy,

I have the same problem with the Scrollpanel. I tried the solution of Paul Robinson, but nevertheless nothing happens.
Here's my code:


public static ScrollPanel scrollPanel;

// ...


private void loadInputFunctions() {
        input.addKeyDownHandler(new KeyDownHandler() {

            @Override
            public void onKeyDown(KeyDownEvent event) {
                            // ...
                    }
                    input.setText(">>");
                    Scheduler.get().scheduleDeferred(
                            new Scheduler.ScheduledCommand() {
                                @Override
                                public void execute() {
                                    scrollPanel.scrollToBottom();
                                }
                            });

                }

            }
        });
    }

Thanks in advance.



















adanz...@gmail.com

unread,
Jun 12, 2013, 5:42:24 PM6/12/13
to google-we...@googlegroups.com
Hy,

I have the same Problem. I tried the solution of Paul Robinson, but nevertheless, nothing happens.
Where is my mistake? Here is my code:

public static ScrollPanel scrollPanel;
// ...
private void loadInputFunctions() {
        input.addKeyDownHandler(new KeyDownHandler() {

            @Override
            public void onKeyDown(KeyDownEvent event) {
                if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {

                    // ...
                    }
                    input.setText(">>");
                    Scheduler.get().scheduleDeferred(
                            new Scheduler.ScheduledCommand() {
                                @Override
                                public void execute() {
                                    scrollPanel.scrollToBottom();
                                }
                            });
                }

            }
        });
    }

Thanks in advance.
> To unsubscribe from this group, send email to google-web-toolkit+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages