CellTable - how to load just one page?

57 views
Skip to first unread message

Magnus

unread,
Oct 26, 2011, 1:20:20 AM10/26/11
to google-we...@googlegroups.com
Hi,

I have a large list, which I do not want to load all at once. I would like to load and display just one page and let the user navigate to other pages.

The problem I see with CellTable is that it needs the whole list at once (setRowData). So I have to transfer all the data. Is it possible just to load the data for one page, and load the next portion if the page changes?

Other questions:
How can I add a simple navigation buttons (page next, last) to a CellTable?

Finally, assume that the CellTable resides within a panel with a given size. Is it possible to set the page size so that there are no scroll bars, i. e. fill the panel with cell rows without exceeding the available space?

Thanks
Magnus

Thomas Broyer

unread,
Oct 26, 2011, 9:04:26 AM10/26/11
to google-we...@googlegroups.com


On Wednesday, October 26, 2011 7:20:20 AM UTC+2, Magnus wrote:
Hi,

I have a large list, which I do not want to load all at once. I would like to load and display just one page and let the user navigate to other pages.

The problem I see with CellTable is that it needs the whole list at once (setRowData). So I have to transfer all the data. Is it possible just to load the data for one page, and load the next portion if the page changes?

Are you kidding me? Just 2 days ago you asked how to display the whole data you loaded because CellTable uses paging by default!

Either you have the whole data set and you can call setRowData(List), which is just a shorthand for setRowCount(list.size());setRowData(0,list);
Or you have only a portion of the data (generally the size of a page, but not necessarily) and you'll call setRowCount (either you know exactly how many items the whole dataset contains, and you can call setRowCount(int), or you're not sure and you'll call setRowCount(int,boolean) passing 'false' as the second argument; if you really don't know, you can pass any big value as the first argument, and then adjust it later when you've reached the end of the dataset, ofr instance) and setRowData(int,List).

Other questions:
How can I add a simple navigation buttons (page next, last) to a CellTable?

SimplePager ?

Finally, assume that the CellTable resides within a panel with a given size. Is it possible to set the page size so that there are no scroll bars, i. e. fill the panel with cell rows without exceeding the available space?

Only if you know in advance the height of a rendered row. You could also, I guess, reduce the page-size once loaded if you detect that scrollbars are necessary, until they're no longer needed (i.e. load a bit too many and then only show what fits in the display area).

David

unread,
Oct 26, 2011, 10:19:08 AM10/26/11
to Google Web Toolkit
"Only if you know in advance the height of a rendered row. "

Hi Thomas,

I'm close to a solution to providing dynamic retrieval of data via
scrolling. The CellList example provided in the GWT Showcase does
not work for me because is doesn't let the user immediately scroll to
any portion of the list not already loaded. Hence you get a water
pump effect as you have to bring the scrollbar all the way to the
bottom in order to request more data.

Right now I am determing the scrollpanel height by multiplying two
constants: VISIBLE_ITEMS_IN_VIEW * ROW_HEIGHT
I determine ROW_HIGHT by testing with some data and inspecting the
value of cellTable.getRowElement(0).getClientHeight().

Do you know any way of determining the "height of a rendered row" at
runtime and before setting the height of the scrollpanel ?

thanks
David

Magnus

unread,
Jan 17, 2012, 11:46:47 AM1/17/12
to google-we...@googlegroups.com
Sorry for the delay!


I have a large list, which I do not want to load all at once. I would like to load and display just one page and let the user navigate to other pages.
The problem I see with CellTable is that it needs the whole list at once (setRowData). So I have to transfer all the data. Is it possible just to load the data for one page, and load the next portion if the page changes?

Are you kidding me? Just 2 days ago you asked how to display the whole data you loaded because CellTable uses paging by default!

This was another question.
 
Either you have the whole data set and you can call setRowData(List), which is just a shorthand for setRowCount(list.size());setRowData(0,list);
Or you have only a portion of the data (generally the size of a page, but not necessarily) and you'll call setRowCount (either you know exactly how many items the whole dataset contains, and you can call setRowCount(int), or you're not sure and you'll call setRowCount(int,boolean) passing 'false' as the second argument; if you really don't know, you can pass any big value as the first argument, and then adjust it later when you've reached the end of the dataset, ofr instance) and setRowData(int,List).

Ok, but these calls have to be triggered somehow, e. g. when the user clicks "next page". How is this done?


 Magnus

Thomas Broyer

unread,
Jan 19, 2012, 10:43:05 AM1/19/12
to google-we...@googlegroups.com
Using a RangeChangeEvent.Handler, or more simply an AbstractDataProvider (or AsyncDataProvider).

When clicking "next page" in the "pager" (let's say we have a SimplePager, or any AbstractPager; if you roll your own code, then just mimic what these widgets do), it'll setVisibleRange on your CellTable, which will then fire a RangeChangeEvent. An AbstractDataProvider listens to this event (but you can register your own RangeChangeEvent.Handler if you prefer) and calls onRangeChanged which you have to implement (unless you're using a ListDataProvider) and call updateRowCount and/or updateRowData with the new values. That will call setRowCount and setRowData on your CellTable to update the display.

Reply all
Reply to author
Forward
0 new messages