PDA

View Full Version : focusRow help?



benny
17 Aug 2009, 6:27 AM
Hi,

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,
collapsible:false,
height:460,
width:665,
border:false,
layout:'fit',
loadMask: {msg:'Loading, Please wait...'},
viewConfig: {
forceFit: true
}
}),

// other grids
};

My code which captures the Grid data refresh:


dataGrid.gridA.getView().on({
beforerefresh: function(){
if(globalRowIndex == "") {
dataGrid.gridA.getSelectionModel().selectRow(0);
} else {
alert('index: ' + globalRowIndex); // returns 9 for example
dataGrid.gridA.getView().focusRow(globalRowIndex);

);
}
}
});

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.

Condor
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?

Lukman
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.

benny
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

Condor
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.

benny
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?

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

benny
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.