PDA

View Full Version : updating a TreeGrid



g1_
21 Nov 2009, 7:06 AM
Maybe someone can advise me on the appropriate way to do this.

I have a TreeGrid containing a list of contacts along with their status/presence. What I was doing was when a status changes I removed the TreeGrid and made a new one with the updated data. This working fine during my testing as my list wasn't that long. Now I'm trying to put it on a live system, and this live system has enough contacts to require a scroll bar. The problem with removing the TreeGrid and adding a new one is that the scrollbar jumps to the top whenever a status is updated.

So now I'm trying to modify the data without removing and re-adding the TreeGrid, but not having any luck. The changes don't seem to reflect in the TreeGrid. If I resize the window and force the TreeGrid to re-render the changes still aren't there. Here's my Code:



//updates the contacts list
public void updateUserStatus(Person person) {

for (int i = 0 ; i < groupTree.getStore().getCount() ; i++) {
ModelData model = groupTree.getStore().getAt(i) ;
if ( model.get("name").equals(person.getName()) ) {
model.set("status","- "+person.getStatus()) ;
model.set("icon",person.getStatusColour()) ;
}
}//end: for i

}//end: method set contacts
Any advice on how to this would be greatly appreciated.


It looks like I can replace my for loop with a listStore.findModel(String key) call. But that's not important right now.

sven
21 Nov 2009, 7:31 AM
You need to work on the TreeStore:


groupTree.getTreeStore()...

g1_
21 Nov 2009, 7:56 AM
Thanks for the reply Sven.

It's still not quite working though. Here's what I currently have:



//updates the contacts list
public void updateUserStatus(Person person) {

List<ModelData> groupData = groupTree.getTreeStore().getAllItems() ;
for (int i = 0 ; i < groupData.size() ; i++) {
ModelData model = groupData.get(i) ;
if ( model.get("name").equals(person.getName()) ) {
model.set("status","- "+person.getStatus()) ;
model.set("icon",person.getStatusColour()) ;
}
}//end: for i

}//end: method set contacts


Again, the changes don't seem to appear on the screen. I'm not sure if the underlying data is getting modified but not displayed or if the underlying data is not getting updated.

sven
21 Nov 2009, 10:04 AM
Of that type are your models?

g1_
22 Nov 2009, 3:42 AM
private ModelData newItem(String name, String status, String icon) {
ModelData m = new BaseModelData() ;
m.set("name", name ) ;
if (status != null) m.set("status", "- "+status) ;
m.set("icon", icon) ;
return m;
}


They're just BaseModelData's (done in the same way as the examples).

g1_
22 Nov 2009, 4:25 AM
The plot thickens:

I've added a StoreFilterField to this TreeGrid. I've noticed that if I update a record in the TreeGrid the change does not display. If I resize the window the change does not display. Calling layout() after updating the store doesn't help display the changes. But if I filter the TreeGrid the change does display. So it's definitely a rendering thing.

sven
22 Nov 2009, 5:28 AM
You will need to use BaseModel, and set monitorchanges to true in the store.

g1_
22 Nov 2009, 5:41 AM
Legend! That's done it for me :)

Thanks, Sven!

g1_
22 Nov 2009, 9:35 AM
One more question.

When I update the ModelData (which now does display) the scrollbar jumps to the changed entry. Is it possible to not move the scrollbar? I have a long list of contacts which requires a scrollbar to look through and would not like the scrollbar to jump around as the contacts status' update.

sven
22 Nov 2009, 9:36 AM
This is because the row gets focused. We removed this already because this is in most places unwanted.

2.1 will contain this change.

g1_
22 Nov 2009, 10:17 AM
Another one more question:

The filter I added to the TreeGrid works great on my test server but on the production server (with >200 contacts) it doesn't seem to work. Is there a limit after which the filtering stuff will not work?

g1_
22 Nov 2009, 11:56 PM
The filtering is fixed now. Turns out I broke that with a change I made.

Sven, is it possible to migrate the change made in 2.1 to the TreeGrid to 2.0 by overloading a method, or some other means? Just looking for a temporary measure until I can get my hands on 2.1 :)

Thanks,
Jeff