Fixing a column in DataGrid

236 views
Skip to first unread message

Raphael André Bauer

unread,
May 29, 2013, 10:11:26 AM5/29/13
to google-web-toolkit
Hi,


I am using a DataGrid that is larger than the viewport. If the user
scrolls to the right I want the first x columns to be fixed so the
user "knows" in which line she is.

Some time ago someone has asked a similar question - but the answers
are not 100% satisfactory imho.
http://stackoverflow.com/questions/10904518/how-to-make-gwt-datagrid-have-its-first-column-fixed-and-scroll-horizontally-and

Is there a simple working solution to this? I only need support for
relatively new browsers.


Many thanks in advance!


Cheers,


Raphael

Jens

unread,
May 29, 2013, 1:24:35 PM5/29/13
to google-we...@googlegroups.com
Before deep diving into DataGrid, I think my first "make it work" approach would be to just use two DataGrids and add both to the same DataProvider, so that their data is in sync with each other. The first one would contain the static x columns while the second one contains the remaining columns. Only the second one would allow horizontal scrolling then.

Do you also use vertical scrolling in your DataGrid? If not, then I would try to add position:fixed to each cell of the first x columns. With position:fixed you probably would not need to recalculate anything while scrolling horizontally.

-- J.

Raphael André Bauer

unread,
May 30, 2013, 6:36:01 AM5/30/13
to google-we...@googlegroups.com
Hi Jens,

thanks for the good suggestion - I'll try that first...

Best,

Raphael

Raphael André Bauer

unread,
Jun 14, 2013, 5:24:30 AM6/14/13
to google-we...@googlegroups.com
On Wed, May 29, 2013 at 7:24 PM, Jens <jens.ne...@gmail.com> wrote:
Hi Jens,


thanks for the suggestion. I had now time to check it out and it works
nicely :) The problem I have now is with vertical scrolling. The left
datagrid scrolls independently of the right datagrid...

Do you have any suggestions how to sync the scrolling?


Thanks :)

Raphael

Jens

unread,
Jun 14, 2013, 5:42:59 AM6/14/13
to google-we...@googlegroups.com
Well, add a scroll handler to the right ScrollPanel and set the current scroll position on the left ScrollPanel.

-- J.

Raphael André Bauer

unread,
Jun 17, 2013, 6:50:28 AM6/17/13
to google-we...@googlegroups.com
On Fri, Jun 14, 2013 at 11:42 AM, Jens <jens.ne...@gmail.com> wrote:
> Well, add a scroll handler to the right ScrollPanel and set the current
> scroll position on the left ScrollPanel.

Hi Jens,


thanks for that :) It worked the way you described it. With one tiny
caveat. DataGrids don't export their ScrollPanel (Maybe I got you
wrong).

I simply extended an original DataGrid and exposed their ScrollPanel like so:
public ScrollPanel getScrollPanel() {
HeaderPanel header = (HeaderPanel) getWidget();
return (ScrollPanel) header.getContentWidget();
}

This made syncing the scrolling positions of my two DataGrids quite
simple and I know have one fixed column in my datagrid.


Thanks for your help!


Best,

Raphael
Reply all
Reply to author
Forward
0 new messages