PDA

View Full Version : ExtJS 4.1 - Cannot call 'getProxy' of undefined



bomslang
8 Sep 2012, 7:01 AM
Folks,

I am trying to load a grid with JsonP proxy as shown in this example.
http://docs.sencha.com/ext-js/4-1/#!/example/grid/paging.html
(http://docs.sencha.com/ext-js/4-1/#!/example/grid/paging.html)
Below is my code class :-



Ext.define('Ext.app.SampleGrid', {
extend: 'Ext.grid.Panel',
alias: 'widget.gridportlet',

renderTopic: function(value, p, record) {
return Ext.String.format(
'<b><a href="http://sencha.com/forum/showthread.php?t={2}" target="_blank">{0}</a></b><a href="http://sencha.com/forum/forumdisplay.php?f={3}" target="_blank">{1} Forum</a>',
value,
record.data.forumtitle,
record.getId(),
record.data.forumid
);
},

createModel: function() {
debugger;;
return Ext.create('Ext.data.Model', {
fields: [
'title', 'forumtitle', 'forumid', 'username',
{name: 'replycount', type: 'int'},
{name: 'lastpost', mapping: 'lastpost', type: 'date', dateFormat: 'timestamp'},
'lastposter', 'excerpt', 'threadid'
],
idProperty: 'threadid'
});
},

createProxy: function() {
debugger;;
return Ext.create('Ext.data.proxy.JsonP', {
url: 'http://www.sencha.com/forum/topics-browse-remote.php',
reader: {
root: 'topics',
totalProperty: 'totalCount'
},
// sends single sort as multi parameter
simpleSortMode: true
});
},
createStore: function() {
debugger;;
return Ext.create('Ext.data.Store', {
model: this.createModel,
proxy: this.createProxy,
sorters: [{
property: 'lastpost',
direction: 'DESC'
}]
});
},
initComponent: function() {
debugger;;
var pluginExpanded = true;

Ext.apply(this, {
title: 'ExtJS.com - Browse Forums',
store: this.createStore,
disableSelection: true,
loadMask: true,
columns:[{
id: 'topic',
text: "Topic",
dataIndex: 'title',
flex: 1,
renderer: this.renderTopic,
sortable: false
},{
text: "Author",
dataIndex: 'username',
width: 100,
hidden: true,
sortable: true
},{
text: "Replies",
dataIndex: 'replycount',
width: 70,
align: 'right',
sortable: true
},{
id: 'last',
text: "Last Post",
dataIndex: 'lastpost',
width: 150,
renderer: this.renderLast,
sortable: true
}],
});

this.callParent(arguments);
}
});


But, I am getting the below error on console.


Uncaught TypeError: Cannot call method 'getProxy' of undefined


What I am doing wrong ?

vietits
8 Sep 2012, 4:41 PM
When you define or create a store, its model config should be a model name or model class or id of model class, not an instance of model. So try to fix your code as below:


Ext.define('MyModel', {
extend: 'Ext.data.Model',
fields: [
'title', 'forumtitle', 'forumid', 'username',
{name: 'replycount', type: 'int'},
{name: 'lastpost', mapping: 'lastpost', type: 'date', dateFormat: 'timestamp'},
'lastposter', 'excerpt', 'threadid'
],
idProperty: 'threadid'
});


Ext.define('Ext.app.SampleGrid', {
extend: 'Ext.grid.Panel',
alias: 'widget.gridportlet',
...
// createModel: function() {
// debugger;;
// return Ext.create('Ext.data.Model', {
// fields: [
// 'title', 'forumtitle', 'forumid', 'username',
// {name: 'replycount', type: 'int'},
// {name: 'lastpost', mapping: 'lastpost', type: 'date', dateFormat: 'timestamp'},
// 'lastposter', 'excerpt', 'threadid'
// ],
// idProperty: 'threadid'
// });
// },
createProxy: function() {
debugger;;
return Ext.create('Ext.data.proxy.JsonP', {
url: 'http://www.sencha.com/forum/topics-browse-remote.php',
reader: {
root: 'topics',
totalProperty: 'totalCount'
},
// sends single sort as multi parameter
simpleSortMode: true
});
},
createStore: function() {
debugger;;
return Ext.create('Ext.data.Store', {
// model: this.createModel,
model: 'MyModel',
proxy: this.createProxy,
sorters: [{
property: 'lastpost',
direction: 'DESC'
}]
});
},