View Full Version : focusRow help?

17 Aug 2009, 6:27 AM

I'm trying to scroll to a row in a gridPanel once the dataview has refreshed, for some reason I keep getting an error.

My data Grid:

var dataGrid = {
gridA : new Ext.grid.GridPanel({
ds: storeA,
columns: [
{header: "Field 1", width:70, sortable: true,dataIndex: 'field_1'},
{header: "Field 2", width:180, sortable: true, dataIndex: 'field_2'}
stripeRows: true,
loadMask: {msg:'Loading, Please wait...'},
viewConfig: {
forceFit: true

// other grids

My code which captures the Grid data refresh:

beforerefresh: function(){
if(globalRowIndex == "") {
} else {
alert('index: ' + globalRowIndex); // returns 9 for example


The var 'globalRowIndex' contains an integer of the row (which was selected before the refresh)... for example 9.

The data refresh is called using: storeA.reload();

The error I get in firebug/safari is something like:

TypeError: Result of expression 'this.getRow(b)' [undefined] is not an object. - ext-all.js (line 11)

Nobody else seems to have the problem, so I must be doing this wrong. Should I use a some other capture event in place of 'beforerefresh'? or any other ideas?

This is for version 3.0

Many thanks for reading, I hope you can help.

17 Aug 2009, 6:43 AM
'beforerefresh'? Don't you mean 'refresh'?

Also, don't you have to check if that rowIndex still exists after the grid has been refreshed?

17 Aug 2009, 6:45 AM
'beforerefresh' means before the gridview is refreshed. If you want it done after it is refreshed, hook onto the 'refresh' event instead.

17 Aug 2009, 6:58 AM
You guys are correct, the event 'beforerefresh' is not the correct one to use. However, changing it to 'refresh' produces the same error. Can you point me to the available events in the docs? I searched but cannot find them listed for the GridPanel (hence the reason I ended up with beforerefresh).

I still cannot get the grid to scroll down to the selected row. focusRow is supposed to scroll right?

many thanks

17 Aug 2009, 7:06 AM
You are using grid.getView().on(...) which should have alerted you to the fact that beforerefresh and refresh are events of GridView and not of GridPanel.

18 Aug 2009, 2:31 AM
I was not aware that getView was part of gridView, thanks.

Any idea how I can scroll down to a selected row? is this possible even possible?

18 Aug 2009, 3:33 AM
focusRow should scroll the grid to make the row visible. Doesn't it work for you?

18 Aug 2009, 6:10 AM
focusRow fails to work for me.

I ended up using the other method of disabling the scrollToTop on the grid onLoad (I found details of this in the FAQ's for version 2):

viewConfig: {
forceFit: true,
onLoad: Ext.emptyFn,
listeners: {
beforerefresh: function(v) {
v.scrollTop = v.scroller.dom.scrollTop;
v.scrollHeight = v.scroller.dom.scrollHeight;
refresh: function(v) {
v.scroller.dom.scrollTop = v.scrollTop +
(v.scrollTop == 0 ? 0 : v.scroller.dom.scrollHeight - v.scrollHeight);

Reference : Maintaining_scroll_position_when_store_is_reloaded (http://extjs.com/learn/Ext_FAQ_Grid#Maintaining_scroll_position_when_store_is_reloaded)

Thanks for your help and pointers.