PDA

View Full Version : focusRow jumps back to top



jnjc
22 Jun 2011, 3:28 PM
Hi All,

I am trying to have a particular row come into view after I reload the grid. I am using the following code:


referrersGrid.getStore().reload({callback:function(){
var rowRec = referrersGrid.getSelectionModel().getSelected();
var rowIndex = referrersGrid.getStore().indexOf(rowRec);
alert(rowIndex);
referrersGrid.getView().focusRow(rowIndex);
}});


The grid does scroll the selected row into view, but then scrolls back to the top. I have found some mention of this behavior when searching the forums but no mention of how to fix it. I have set deferRowRender to false on the grid definitions but it makes no difference. If I leave the alert box on screen for a couple of seconds before I click it, the grid sometimes does not jump back to the top.

Any ideas on how I can solve this ?

TIA,
JC

jarlau
22 Jun 2011, 5:13 PM
try use load event of store.



store.on('load', function(ds) {
// focus row here.
});

jnjc
22 Jun 2011, 5:49 PM
Hi jarlau,

Thanks for the reply, unfortunately that didn't work either. I added the following code, just after I declared my grid:


referrersStore.on('load',function(ds){ var rowRec = referrersGrid.getSelectionModel().getSelected();
var rowIndex = ds.indexOf(rowRec);
alert(rowIndex);
if (rowIndex >= 0) referrersGrid.getView().focusRow(rowIndex);
});

But as before, it works if I leave the message visible for a second, but if I remove the message it scrolls to the selected row and then jumps back to the top.

Regards,
JC

jarlau
23 Jun 2011, 12:09 AM
Have a brief test and it could be done by first store the last selected index 'beforeload' and get back the index after 'load' with a little delay.



grid.store.on('beforeload',function(ds){
var rowRec = grid.getSelectionModel().getSelected();
var rowIndex = ds.indexOf(rowRec);
grid.lastSelectedIndex = rowIndex;
});
grid.store.on('load',function(ds){
var rowIndex = grid.lastSelectedIndex;
if (rowIndex >= 0) grid.getView().focusRow(rowIndex);
}, grid, {buffer: 50});