PDA

View Full Version : Get grid's first row



spillo491
12 Oct 2011, 11:26 PM
I need to get the first row of a grid, can you help me ?



var tab = Ext.select('table.x-grid-table', 'tabHistory');
var tr = Ext.select('tr', tab.item(0).dom);

northbridge
13 Oct 2011, 4:22 AM
var sm = this.gridId.getSelectionModel();
var record = sm.select(0);

mankz
13 Oct 2011, 4:25 AM
grid.getView().getNode(0);

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.view.AbstractView-method-getNode

spillo491
14 Oct 2011, 12:16 AM
Thanks ;)

mad8
4 Jul 2012, 9:21 PM
Can anyone please help me? I tried:
grid.getSelectionModel().select(0);
grid.getSelectionModel().select(grid.store.getAt(0));
grid.selModel.select(0);
grid.getView().select(0);
grid.getView().getNode(0);
Nothing works. I use 4.1. I need to select first grid row.

redraid
5 Jul 2012, 1:27 AM
grid.getView().select(0) works for me in 4.1 -

Ext.create('Ext.data.Store', {
storeId:'simpsonsStore',
fields:['name', 'email', 'phone'],
data:{'items':[
{ 'name': 'Lisa', "email":"[email protected]", "phone":"555-111-1224" },
{ 'name': 'Bart', "email":"[email protected]", "phone":"555-222-1234" },
{ 'name': 'Homer', "email":"[email protected]", "phone":"555-222-1244" },
{ 'name': 'Marge', "email":"[email protected]", "phone":"555-222-1254" }
]},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});

Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{ header: 'Name', dataIndex: 'name' },
{ header: 'Email', dataIndex: 'email', flex: 1 },
{ header: 'Phone', dataIndex: 'phone' }
],
height: 200,
width: 400,
renderTo: Ext.getBody(),
tbar: [
{text: 'Select 1st row', handler: function (btn) {
var grid = btn.up('grid');

grid.getView().select(0);
}}
]
});

sword-it
5 Jul 2012, 3:18 AM
Hi!

You can also do the same in a callback when your grid's store load.
Try this:-




store.load({
callback: function (records, operation, success) {
grid.getView().select(0);
}
})

redraid
5 Jul 2012, 4:14 AM
I think is better select view item(s) in viewready (http://docs.sencha.com/ext-js/4-1/#!/api/Ext.view.AbstractView-event-viewready) event:


viewready: function (view) {
view.select(0);
}

//wbr

mad8
5 Jul 2012, 4:42 PM
redraid, thank you so much for that code example, finally I understand where I go wrong.