CellTable - how to avoid unnecessary onRangeChange events?

310 kali dilihat
Langsung ke pesan pertama yang belum dibaca

Magnus

belum dibaca,
28 Nov 2012, 10.43.2428/11/12
kepadagoogle-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

belum dibaca,
29 Nov 2012, 09.11.3129/11/12
kepadagoogle-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

belum dibaca,
29 Nov 2012, 09.36.2429/11/12
kepadagoogle-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

Balas ke semua
Balas ke penulis
Teruskan
0 pesan baru