Reputation: 10346
I have a GWT CellTable
contained in a ScrollPanel
. The CellTable
is set to use a SingleSelectionModel<T
> I am programatically setting the selected row, which is working fine. However, the cell table isn't scrolled to the selected row. Is there a way I can both select the row and scroll so the selected row is visible?
Upvotes: 2
Views: 3175
Reputation: 10346
Andrei was on the right track, but setScrollTop(int) gives the number of pixels to scroll, not the index to scroll to. What works is:
myTable.getRowElement(index).scrollIntoView();
this adjusts the scrolling so that the element is in view. Note that if your table scrolls horizontally, scrollIntoView() will scroll it all the way to the right in an attempt to show all of the cell. I didn't want this behavior, so I subsequently called:
myScrollViewThatContainsCellTable.scrollToLeft();
Upvotes: 6
Reputation: 41100
Try
myTable.getRowElement(index).setScrollTop(0);
where index is the index of a selected row.
Upvotes: 1