PDA

View Full Version : selectFirstRow, again



oddy
12 Jul 2009, 9:19 PM
Is it possible to make it work without deferRowRenderer? I use this approach (initComponent method in extended EditorGridPanel):


...
this.store.on("load", function(store, rs, op){
this.getSelectionModel().selectFirstRow.defer(10, this.getSelectionModel());
}, this);

Application.PartnersGrid.superclass.initComponent.apply(this, arguments);
this.store.load();
But every time this grid is removed and then added again to a container I get "this.grid is undefined" in firebug (ext-all-debug.js in a line 61989 in a 4805 rev. from svn). However, it selects the row. But I have to get rid of this error in any way. Any help/suggestions?

Animal
12 Jul 2009, 11:13 PM
Removed? By default, Components are destroyed on remove.

Condor
13 Jul 2009, 12:21 AM
I would use:

var grid = new Ext.grid.GridPanel({
...
viewConfig: {
...
afterRender: function(){
this.constructor.prototype.afterRender.apply(this, arguments);
this.grid.getSelectionModel().selectFirstRow();
}
}
});
(deferRowRender setting doesn't matter)

oddy
13 Jul 2009, 4:03 AM
I would use:

var grid = new Ext.grid.GridPanel({
...
viewConfig: {
...
afterRender: function(){
this.constructor.prototype.afterRender.apply(this, arguments);
this.grid.getSelectionModel().selectFirstRow();
}
}
});(deferRowRender setting doesn't matter)
Your approach was the first I used, but it doesn't worked for me. In my case this code selects the row and then, in a second, deselects it

oddy
13 Jul 2009, 4:06 AM
Removed? By default, Components are destroyed on remove.
And that's really great. But that is not an explanation of what is going on.

Condor
13 Jul 2009, 4:30 AM
Your approach was the first I used, but it doesn't worked for me. In my case this code selects the row and then, in a second, deselects it

It depends. Does your store get loaded before of after you render the grid?

oddy
13 Jul 2009, 5:06 AM
Store gets loaded just after the base initialization (see snippet). So it's before the actual rendering, I guess. At least it starts loading before rendering :-/

oddy
22 Jul 2009, 4:05 AM
Anyone? Please, help.

Condor
22 Jul 2009, 5:17 AM
If you render your grid first and load the store afterwards you can simply use a load event handler on the store.


grid.getStore().on('load', function(){
grid.getSelectionModel().selectFirstRow();
});

or, if you want to override GridView instead:

grid.getView().onLoad = grid.getView().onLoad.createSequence(function(){
grid.getSelectionModel().selectFirstRow();
});

oddy
22 Jul 2009, 6:15 AM
Something's wrong again (:|



Ext.override(Ext.grid.GridView, {
onLoad : Ext.grid.GridView.onLoad.createSequence(function(){
this.grid.getSelectionModel().selectFirstRow();
})
});


Ext.grid.GridView.onLoad is undefined

oddy
22 Jul 2009, 6:20 AM
If you render your grid first and load the store afterwards you can simply use a load event handler on the store.


grid.getStore().on('load', function(){
grid.getSelectionModel().selectFirstRow();
});
...

It doesn't work if I won't defer selectFirstRow method. In my first message in the thread I mentioned, that it raises an error "this.grid is undefined", so this is what works for me now:



Ext.override(Ext.grid.GridPanel,{
selModel: new Ext.grid.RowSelectionModel({singleSelect: true})
, initComponent: function() {
if (this.getSelectionModel().selectFirstRow) {
this.store.on("load", function(store, rs, op){
var sm = this.getSelectionModel();
if (sm.grid && sm.grid.store){
sm.selectFirstRow.defer(10, this.getSelectionModel());
}
}, this);
}
Ext.grid.GridPanel.superclass.initComponent.apply(this, arguments);
}
}


But it's ugly. But it works.

Condor
22 Jul 2009, 6:20 AM
You're missing:

Ext.override(Ext.grid.GridView, {
onLoad : Ext.grid.GridView.prototype.onLoad.createSequence(function(){
this.grid.getSelectionModel().selectFirstRow();
})
});

oddy
22 Jul 2009, 6:25 AM
You're missing:

Ext.override(Ext.grid.GridView, {
onLoad : Ext.grid.GridView.prototype.onLoad.createSequence(function(){
this.grid.getSelectionModel().selectFirstRow();
})
});
WOOOOOOW! :D This works perfectly, thanks! Sorry for my carelessness.