CellTable - how to avoid unnecessary onRangeChange events?

310 views
Skip to first unread message

Magnus

unread,
Nov 28, 2012, 10:43:24 AM11/28/12
to google-we...@googlegroups.com
Hi,

I found that my CellTable sends unnecessary onRangeChange events in a specific situation:

- The data source changes, e. g. the user selects another chat room.
- The new row count is less than the old one.

Then, when calling the data provider's updateRowCount method the GWT code recognizes that the current range exceeds the row count and corrects the range somhow, triggering an onRangeChange event.
Independend of this, the application also as an idea which records to show and also sets the new range.

In the end, the page is loaded twice. Can we avoid this?

Magnus

Rafael Paulino

unread,
Nov 29, 2012, 9:11:31 AM11/29/12
to google-we...@googlegroups.com
Magnus, Hi.

I didn't found an easy and simple solution for that.

In my application I wrote a "DataManager" which is an AsyncDataProvider and has some cache functionality. So when I get an onRangeChange event I just go to server when it's really needed, fetching only the missing range.

It do a lot of things, but only this class for me is getting 800 lines :( Of course, this cache functionality is smaller than this, but still complex.

I haven't tested yet the performance of my code.

I could share something with you, if you are interested in. 

Magnus

unread,
Nov 29, 2012, 9:36:24 AM11/29/12
to google-we...@googlegroups.com
Hi Rafael,

thank you for offering me your solution.
But in the meantime I found a very simple solution:

The application has to set the new range *before* a call to updateRowCount is made!

The first thing I do right after the data source (chat room) changed is to load the new row count.
But *before* passing this new row count to the data provider (which would trigger an onRangeChange event then), I set the range myself to a valid interval.
Finally, *after* this, I call updateRowCount.

Pseudocode: 

void onSelectChatRoom:()
{
 loadNewRowCount ();
}

void onLoadNewRowCount (int cnt)
{
 Range r = getLastPageRangeForCurrentRoom(cnt);
 tbl.setVisibleRangeAndClearData (r,true); // triggers one onRangeChange event

 pvd.updateRowCount (cnt); // does not trigger a second onRangeChange event anymore!
}

HTH
Magnus

Reply all
Reply to author
Forward
0 new messages