PDA

View Full Version : Extending GridPanel: cm is undefined



randomuser01
26 Sep 2008, 6:51 AM
Any ideas why this code would throw the following error?

cm is undefined (ext-all-debug.js line 31291)
for(var i = 0, len = cm.getColumnCount(); i < len; i++){






CompanyPanel = function( config ) {
var allCounterPartiesDS = new Ext.data.Store({
id: '_allCounterpartiesStore',
proxy: new Ext.data.HttpProxy({
url: '/GetReferenceData.aspx?type=Company', method: 'GET'
}),
reader: new Ext.data.XmlReader({
record: 'Name'
}, [
{ name: 'Name' },
{ name: 'Desk' }
]),
autoLoad: true,
sortInfo:{field:'Name', direction:'ASC'}
});

var checkSM = new Ext.grid.CheckboxSelectionModel();
var colModel = new Ext.grid.ColumnModel([
checkSM,
{id:'Name',header: 'Name',sortable: true,locked:false,dataIndex: 'Name', width:'50px'},
{id:'Desk',header: 'Desk',sortable: true,locked:false,dataIndex: 'Desk'}
]);
var grid = new Ext.grid.GridPanel( {
ds: allCounterPartiesDS,
region: 'center',
cm: colModel,
sm: checkSM,
frame: true
} );

Ext.apply(this, {
labelWidth: 50, frame:false, bodyStyle:'padding:5px 5px 0',
width: 250, defaults: {width: 230},
items: [ grid ]
});

Ext.grid.GridPanel.superclass.constructor.call(this, config);
}

Animal
26 Sep 2008, 6:53 AM
You are not calling the GridPanel constructor from your subclass.

You are calling the Panel constructor.

randomuser01
26 Sep 2008, 7:00 AM
Animal,

Could you please elaborate? Ext.GridPanel isn't defined so that's why I switched to Ext.grid.GridPanel.superclass.

Thanks

randomuser01
26 Sep 2008, 7:01 AM
And CompanyPanel.superclass.constructor.call(this, config); throws the same error.

Thanks

Animal
26 Sep 2008, 7:05 AM
Yes, that's because you are not actually extending GridPanel. You've just defined a constructor.

Read the tutorial about extending.

Condor
26 Sep 2008, 7:06 AM
Here is your corrected example:

CompanyPanel = function(config) {
var allCounterPartiesDS = Ext.StoreMgr.lookup('_allCounterpartiesStore'); // <-- store ids are unique
if (!allCounterPartiesDS) {
allCounterPartiesDS = new Ext.data.Store({
id: '_allCounterpartiesStore',
proxy: new Ext.data.HttpProxy({
url: '/GetReferenceData.aspx?type=Company', method: 'GET'
}),
reader: new Ext.data.XmlReader({
record: 'Name'
}, [
{ name: 'Name' },
{ name: 'Desk' }
]),
autoLoad: true,
sortInfo:{field:'Name', direction:'ASC'}
});
}
var checkSM = new Ext.grid.CheckboxSelectionModel();
var colModel = new Ext.grid.ColumnModel([
checkSM,
{id:'Name',header: 'Name',sortable: true,locked:false,dataIndex: 'Name', width:'50px'},
{id:'Desk',header: 'Desk',sortable: true,locked:false,dataIndex: 'Desk'}
]);
CompanyPanel.superclass.constructor.call(this, Ext.apply({
ds: allCounterPartiesDS,
region: 'center',
cm: colModel,
sm: checkSM,
frame: true
}, config)); // <-- apply config to default config
}
Ext.extend(CompanyPanel, Ext.grid.GridPanel, { // <-- extend the class!
// Optional new or overridden methods
});

randomuser01
26 Sep 2008, 7:15 AM
Thank you both, Condor and Animal.

Animal
26 Sep 2008, 7:47 AM
It still has



Ext.grid.GridPanel.superclass.constructor.call(this, Ext.apply({


Which calls the Panel constructor.

randomuser01
26 Sep 2008, 8:19 AM
Thanks Animal. I've modified it to



CounterpartyPanel.superclass.constructor.call(this,
Ext.apply({
ds: allDS,
region: 'center',
cm: colModel,
sm: checkSM,
frame: true
},
config)
);

randomuser01
26 Sep 2008, 11:10 AM
When I attempt to read the selections from this extended gridPanel, I get zero selections.

var grid = Ext.getCmp('_customGrpGrid');
alert(grid.selModel.getSelections().length);

Is there anything additional I need to do to expose selections?

Thanks

randomuser01
26 Sep 2008, 11:14 AM
Whoops; was looking at the wrong id, sorry.