determine what table rows and columns are *actually* visible? (for scrollIntoView purposes.)

43 views
Skip to first unread message

Linus Kamb

unread,
May 13, 2020, 5:49:34 PM5/13/20
to GWT Users
I have a DataGrid with a pager with a page size of 50 inside a ScrollPanel.  When I ask the grid for the visible range, it give me a range of 50 rows, the size of the page.   But what I can actually see at any given time inside the ScrollPanel is often considerably fewer rows than the page size.

Is there any way to determine what rows and columns are *actually* visible in the viewport of the ScrollPanel?

The driver behind this is that I want to be able to programmatically scroll a row+cell in to view, but I would like to scroll so the row+cell is more or less in the center of the view, instead of just scrolled in to view at the edge.  What I've tried to do is pick a row / column that is either farther down / right or up / left so scroll in to view, but those corrections depend on what is currently visible.

Perhaps there is a "correct" way to do this.

Thanks in advance.
- Linus

Thomas Broyer

unread,
May 14, 2020, 6:25:14 AM5/14/20
to GWT Users
You can get the actual <tr> element using getRowElement() and compute everything from there, based on the element's offsetParent, offsetTop and offsetLeft.

BTW, depending on the browsers you need to support, you might be able to "just" use scrollIntoView with an options dictionary to center the cell: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
Reply all
Reply to author
Forward
0 new messages