views:

1121

answers:

1

I have a SmartGWT webapp that uses a TreeGrid with a dataSource. I would like this treeGrid to preselect values saved in a cookie. I have gotten the value to be saved in the cookie correctly, however I have tried several different methods of getting the treeGrid to select these values and I can not get it to work. I am attempting to do this in the onmoduleLoad method in my entry point.

I have tried:

Cookies.setCookie( "selectedUnit", TreeGrid.getSelectedPaths() )

to set the cookie and then when the page is reloaded:

TreeGrid.setSelectedPaths( Cookies.getCookie("selectedUnit" )
When I could not get that to work, I tried storing just the id of the item selected:

Cookies.setCookies( "selectedUnit", TreeGrid.getSelected().getAttribute("id") )

and then onLoad attempting to find that record and select it:

TreeGrid.selectRecord( TreeGrid.getTree().find("id", Cookies.getCookie("selectedUnit") ) )

This did not work either, so finally I tried storing TreeGrid.getSelectedState() and upon retrieving that value form the cookie onLoad, passing it to TreeGrid.setSelectedState() similar to my first attempt, but passing state instead of path.

I could not get any of these things to work. Can I not tell the TreeGrid to select an item in the 'OnmoduleLoad' method? Is this action only valid after the TreeGrid has been drawn? If that is the case where and how can I do this?

Thank you in advance for any help you can give.

A: 

I figured it out:

I ended up using set(/get)SelectedState. The issue I was having was by calling setSelectedState in the constructor, it was trying to set the selected state before the data was actually there. I fixed this by setting an onDataArrived handler for the tree and then expanding the tree(to get all of the data) and then setting the selected state.