View Full Version : "remember" grid selection between loads

31 Aug 2008, 10:08 AM
A user clicks on a row in a grid and one row is selected (by highlighting with a blue background) and then the user reloads the grid data and when the reload finishes the same row is still present but nothing is selected, I want to keep the selected row highlighted.

My solution:

sm.addListener(Events.SelectionChange, new Listener<SelectionEvent<BeanModel>>() {
public void handleEvent(SelectionEvent<BeanModel> e) {
selectedItems = e.selection;
}); to remember the selection, and then add a load listener to the loader so when the data comes back from the server you should just call select() on the SelectionModel (actually I do a bit of processing here so models are matched on their primary keys because I don't think a pure .equals() is adequate here - or maybe it is, haven't thought too hard)

anyway my point is that the selection doesn't show up because the grid then gets rendered and all selections are cleared, so I have to put the re-selection in a DeferredCommand. Is there a better cleaner way of achieving this? My way works but it's not pretty code.