Monday, January 12, 2009

ExtJS Tip : Select the first row when grid is loaded

Let's say that you have a grid called "mygrid" and you would like the first row of that grid to be selected when the grid data is loaded. The following snippet of code should work ...

Ext.getCmp('mygrid').store.on('load', function(){
var grid = Ext.getCmp('mygrid');
grid.getSelectionModel().selectRow(0);
grid.fireEvent('rowclick', grid, 0)
}, this, {
single: true
});