PDA

View Full Version : Ext.selection.CheckboxModel help needed



bunty
4 Oct 2012, 6:48 AM
I want to get the 1st column value when i select a row. below code is returning me undefined.



var sm = Ext.create('Ext.selection.CheckboxModel',{ listeners: {
select: function(this1, record, index, eOpts ){
alert(record.get(index));
}
}
});

need inputs.

skirtle
4 Oct 2012, 6:52 AM
The get method of a record returns field values based on their name, not an index. e.g.:


record.get('age')

So just pass it the field name, i.e. the dataIndex, of your first column.

bunty
4 Oct 2012, 6:59 AM
its throwing exception: company not defined


//////////////////////////////////////////////////////////////////////////////////////// // Grid 2
////////////////////////////////////////////////////////////////////////////////////////
var sm = Ext.create('Ext.selection.CheckboxModel',{
listeners: {
select: function(this1, record, index, eOpts ){
alert(record.get(company));
}
}

});
var grid2 = Ext.create('Ext.grid.Panel', {
store: getLocalStore(),
selModel: sm,
columns: [
{text: "Company", width: 200, dataIndex: 'company'},
{text: "Price", renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
{text: "Change", dataIndex: 'change'},
{text: "% Change", dataIndex: 'pctChange'},
{text: "Last Updated", width: 135, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
],
columnLines: true,
width: 600,
height: 300,
frame: true,
title: 'Framed with Checkbox Selection and Horizontal Scrolling',
iconCls: 'icon-grid',
renderTo: Ext.getBody()
});

Elfayer
4 Oct 2012, 7:03 AM
Try this :

alert(this.getSelectionModel().getSelection()[0].data.company);
or (this is the same)

alert(this.getSelectionModel().getSelection()[0].get('company'));

skirtle
4 Oct 2012, 7:04 AM
alert(record.get(company));

Should be:


alert(record.get('company'));