GWT 2.4 DataGrid automatic scrolling when selecting an item

Ümit picture Ümit · Sep 28, 2011 · Viewed 7k times · Source

I am using GWT 2.4's new DataGrid in a project. I configured the DataGrid with a pagesize of 50.
The available screen is not big enough to display all items and thus a vertical scrollbar is shown (this is actually the main purpose for using a DataGrid in the first place).
I attached a SingleSelectionModel to the DataGrid in order to be able to select items.
This works fine so far.

However I also have another widget with which the user can interact. Based on that user action a item from the DataGrid should be selected.
Sometimes the selected item is not in the visible screen region and the user has to scroll down in the DataGrid to see it.
Is there any way to automatically or manually scroll down, so that the selected item is visible?
I checked the JavaDocs of the DataGrid and found no appropriate method or function for doing that.

Answer

ocaner picture ocaner · Sep 28, 2011

Don't know if this works, but you could try to get the row element for the selection and use the scrollIntoView Method.

Example Code:

dataGrid.getRowElement(INDEX_OF_SELECTED_ITEM).scrollIntoView();