PDA

View Full Version : EXTJS 4.x selecting record from grid



neerajbherwal
4 Oct 2011, 11:22 AM
Hello All,

I am new to Extjs and I am stuck at this code. Can not figure out what is the equivalent of this in EXTJS 4.x. I am trying to get the click handlers work in 4.0.

in extjs 3.x, this " record = grid.getStore().getAt(rowIndex);" gives me the record for the row. and this "var fieldName = grid.getColumnModel().getDataIndex(columnIndex);" gives me the fieldname for the column.

In 4.0, i am able to get the fieldname by using -

fieldName = grid.getHeaderCt().getHeaderAtIndex(columnIndex).dataIndex;

but having hard time in getting the record for the row. The only closest i have reached is "record = grid.getSelectionModel().getSelection(); " which gives the array of the records.

Can someone please help me?

Thank you for the help in advance.

scottmartin
5 Oct 2011, 5:57 AM
You are very close ...

Record:

getSelectionModel().getSelection()[0]

Field

getSelectionModel().getSelection()[0].data.field_name

Regards,
Scott

neerajbherwal
5 Oct 2011, 6:49 AM
Thank you very much Scott. Appreciate it.


You are very close ...

Record:

getSelectionModel().getSelection()[0]

Field

getSelectionModel().getSelection()[0].data.field_name

Regards,
Scott

chucs
17 Oct 2011, 12:37 PM
Thank you Scott.

I have found the solution as I'm using selType: 'cellmodel'. Here is the code:

var pos = grid.getSelectionModel().getCurrentPosition();
record = grid.store.getAt(pos.row);
colname = grid.getHeaderCt().getHeaderAtIndex(columnIndex).dataIndex;
cellvalue = record.data[colname];

The solution you provided works for rowmodel well.

Thanks,
Chucs

skirtle
17 Oct 2011, 1:04 PM
You should really use the get() method on the record rather than accessing the data property.


record.get('fieldname');

netemp
17 Oct 2011, 9:07 PM
You should really use the get() method on the record rather than accessing the data property.


record.get('fieldname');

+1 for Skirtle here as record.get('fieldname') is more reliable.

chucs
18 Oct 2011, 6:29 AM
Thank you skirtle. That would be good to know. Thanks chucs