PDA

View Full Version : cm is undefined



ReScorpio
3 Aug 2010, 7:52 AM
hi, i get 'cm is undefined' error when i try to set up grid

cm is undefined
len = cm.getColumnCount()what is strange is that when i debug this with Furebug, at the error breakpoint cm variable IS defined and really contains the column model.

Here is the code itself:

Ext.onReady(function(){


var ttsDataStore = new Ext.data.Store({
id: 'ttsDataStore',
proxy: new Ext.data.HttpProxy({
url: 'ajax.php',
method: 'POST'
}),
baseParams:{task: "gettts", date:"2010-07-18"},
reader: new Ext.data.JsonReader({

root: 'results',
totalProperty: 'total'

},[
{name: 'User', type: 'string', mapping: 'user'},
{name: 'Host', type: 'string', mapping: 'host'},
{name: 'State', type: 'string', mapping: 'state'},
{name: 'Start', type: 'string', mapping: 'start'},
{name: 'End', type: 'string', mapping: 'end'},
{name: 'Lenght', type: 'string', mapping: 'lenght'}
]),
sortInfo:{field: 'user', direction: "ASC"}
});

var ttsColumnModel = new Ext.grid.ColumnModel(
[{
header: 'User',
readOnly: true,
dataIndex: 'user',
width: 50,
hidden: false
},{
header: 'Host',
dataIndex: 'host',
width: 50
},{
header: 'State',
dataIndex: 'state',
width: 50,
},{
header: 'Start',
readOnly: true,
dataIndex: 'start',
width: 50
},{
header: 'End',
dataIndex: 'end',
width: 50,
readOnly: true
},{
header: 'Lenght',
dataIndex: 'lenght',
width: 50
}]
);
//ttsColumnModel.defaultSortable= true;


var viewport = new Ext.Viewport({
layout:"border",
forceLayout: true,
defaults: {

},
items:[{
region:"center",
title:"Okey",
layout:'fit',


items: new Ext.grid.GridPanel({
id: 'ttsGrid',
store: ttsDataStore,
cm: ttsColumnModel,
enableColLock:false,
selModel: new Ext.grid.RowSelectionModel({singleSelect:false})

}),
....


what might be wrong?

Elijah
3 Aug 2010, 2:34 PM
are you calling the load method for the data store?

and try replacing the new Ext.grid with
{xtype:'grid',
id: 'ttsGrid'
...
}

ReScorpio
4 Aug 2010, 3:07 AM
Elijah, thanks for the answer

yes, i have

ttsDataStore.load();
before viewport object definition. Also tried changing to xtype=grid - still the same result.

Btw, here is the example of PHP script output (maybe here's the problem?):


({
"total": 2,
"results": [{
"user": "User1",
"host": "10.1.2.3",
"state": "State1",
"start": "2010-07-18 04:00:00",
"end": "2010-07-18 04:40:00",
"lenght": "0h 40m"
},
{
"user": "User2",
"host": "10.4.5.6",
"state": "State2",
"start": "2010-07-18 04:40:00",
"end": "2010-07-18 05:01:00",
"lenght": "0h 21m"
}]
})
still getting the same 'cm is undefined' :-?

Condor
4 Aug 2010, 3:12 AM
No idea why you get 'cm is undefined', but I do have some remarks:
1. Your sortInfo field and column dataIndex needs to match your field names (and it's case sensitive!).
2. Your layout is overnested. The grid should BE the center region instead of being an item in the center region.
3. Column doesn't have a config option 'readOnly'.
4. It's 'length' and not 'lenght'.

ReScorpio
4 Aug 2010, 3:37 AM
Thanks Condor for your tips,
after changing sortInfo from user to User the grid displayed column headers and rows (before that it was empty at all), but the rows are empty and 'cm is undefined' is still there.
About 'readOnly' property - that was from a tutorial (http://www.sencha.com/learn/Tutorial:Grid_PHP_SQL_Part3) i was partially following.
4th is just a typo, but i 'preserve' it everywhere :)

ReScorpio
4 Aug 2010, 6:28 AM
No idea why you get 'cm is undefined', but I do have some remarks:
1. Your sortInfo field and column dataIndex needs to match your field names (and it's case sensitive!).
2. Your layout is overnested. The grid should BE the center region instead of being an item in the center region.
3. Column doesn't have a config option 'readOnly'.
4. It's 'length' and not 'lenght'.
thanks for your tips Condor,
after replacing sortInfo with User instead of user, column headers appeared and rows are also visible now, but they are empty :(
and i still get the same cm is undefined

readOnly property was taken from a tutorial (http://www.sencha.com/learn/Tutorial:Grid_PHP_SQL_Part3)which I partially follow
4th is just a typo, but it is persisted everywhere :)

ReScorpio
4 Aug 2010, 9:39 AM
Managed to make the grid display data by replacing *name:* properties in JsonReader from capitalized to lower case (User->user), however didn't understand why exactly did it solved the problem with displaying.

And the most unexplainable thing to me - is that despite everything is displayed correctly now, Firebug keeps telling 'cm is undefined' :s

mschwartz
4 Aug 2010, 11:11 AM
Your dataIndex names are Uppercase, and your data field names are lowercase. The data field names have to be the same case as the JSON returned by the server.

You should load your store in the grid's render event handler.

And JsonStore is a lot easier to work with than setting up the store as you have it.