I have a situation where I render items from server in GWT grid on FireFox 3.6+. I have approximately 200 items and I load them in loop:
users = myService.getUsers();
for(User user : users){
myPanel.addUser(user); // Pseudocode. Actually i add some labels and text fields...
}
It tooks a long time to change DOM in this loop, so I got “Unresponsive script” notification. But I can not refactor code or make pagination, I need all 200 items on 1 page loaded at once.
Are there any ways to suppress this notification? To notify browser that my script is not hang, but doing something useful?
UPD Ok, here is my code closer. It is a code from big project, and we have many custom components, so, I think, it has no real value.
myService.getUsersDetails(searchCriteria, new MyCallback<List<User>>)
{
@Override
protected void response(List<User> result)
{
gridExpanderPresenter.clear();
int i = 0;
for (User user: result)
{
UserDetailsView detailsView = detailsViewProvider.get();
gridExpanderPresenter.setPresenter(UsersPresenter.this);
gridExpanderPresenter.add(detailsView.asWidget()); //Here is DOM manipulation i mentioned
if (i++ % 2 == 1)
{
detailsView.setOdd(); //Setting style here
}
detailsView.setData(user);
}
}
});
And I think this can help me…
Several options:
batch your updates using
Scheduler.scheduleIncremental; rendering only 10 users or so at a time (don’t worry, theSchedulerwill run your code as many times as possible in a row before yielding, so it might actually render 50, 100 or 150 users at a time, and then continue 10ms (yes, milliseconds) after)switch to
CellTable; this is a major refactoring, but it’ll give you much better performance than anything else you could do based on widgets (Label,TextBox, etc.)