PDA

View Full Version : Display a default row in grid panel upon launch?



dissectcode
21 Sep 2012, 2:51 AM
Hi all - I'm just starting out with 4.1 (I worked with 3.0 a bit) and I was following this example :

http://docs.sencha.com/architect/2/#!/guide/first_desktop_app

It went great but how do I select a default row to display upon application launch? NO row is selected and I would like to choose the first one to be active by default.


I want to try this which I saw in another post :
grid.getSelectionModel().selectRow(0)

but I don't know where to put it.....Or is there a better way?


Thank you!


The code for the grid, from that Sensha tutorial looks like this:



Ext.applyIf(me, {
dockedItems: [
{
xtype: 'gridpanel',
flex: 1,
dock: 'top',
height: 174,
width: 629,
store: 'DocDataStore',
viewConfig: {

},
columns: [
{
xtype: 'gridcolumn',
autoRender: false,
autoShow: false,
dataIndex: 'manufacturer',
text: 'Manufacturer'
},
{
xtype: 'gridcolumn',
dataIndex: 'model',
text: 'Model'
},
{
xtype: 'gridcolumn',
dataIndex: 'price',
text: 'Price'
},
{
xtype: 'gridcolumn',
dataIndex: 'wiki',
text: 'Wiki'
},
{
xtype: 'gridcolumn',
width: 117,
dataIndex: 'img',
text: 'Img'
}
],
listeners: {
select: {
fn: me.onGridpanelSelect,
scope: me
}
}
}
],

redraid
21 Sep 2012, 4:25 AM
Select record in viewready (http://docs.sencha.com/ext-js/4-1/#!/api/Ext.grid.View-event-viewready) handler:


viewConfig: {
viewready: function (view) {
var firstRecord = view.getStore().getAt(0);

if (firstRecord) view.getSelectionModel().select(firstRecord);
}
},

dissectcode
23 Sep 2012, 2:40 PM
Thank you! I put that inside Architect's MyGridPanel > EventBinding + > viewready

and it is perfect.