6 Feb 2012 10:26 AM #1
Find and focus on a row in TreeGrid
Given a TreeModel, I want to focus on the row that represents the model in TreeGrid.
Normally with regular Grid, I do
int index = grid.getStore().indexOf(m); grid.getView().focusRow(index);
int index = grid.getTreeStore().indexOf(m); grid.getTreeView().focusRow(index);
How do I get the row index in grid? Or how do I get view to focus on a model?
17 Feb 2012 9:30 AM #2
What you're trying to do would be most easily handled by getting the ListStore (not the TreeGridStore) from the TreeGrid and using that to find the index of your model object. You can get the ListStore by calling getStore on TreeGrid. This lets you determine exactly what the row index of the item is using indexOf. At this point, you can focus the appropriate row.
The reason you should be using the ListStore is that this store represents the rows that will actually be displayed, in the order they would be shown. Any nodes that have been hidden because of filtering or collapsed parent nodes will correctly not take up any space. (These nodes themselves are not in the store and will have an index of -1.)
There are a few things to keep in mind if you take this approach. First, the Grid must already have finished rendering. Second, any operation you may be responding to (like expanding, drag and drop, etc.) could result in a change in the index of the item you're interested in.