Error: 'this.proxy' is null or not an object in EXTJS
When i ran this EXTJS code,i got an error 'this.proxy' is null or not an object. Can you help me out regarding this,plzz ?
var myData = [
['J', 'MD'],
['A', 'VA'],
['S', 'DC'],
['M', 'DE'],
['B', 'NJ'],
['N', 'CA'],
['S', 'RT'],
['S', 'CG']
];
var store = new Ext.data.ArrayStore({
totalProperty : 8,
autoLoad : {
params : {
start : 0,
limit : 4
}
},
fields : [ {
开发者_运维知识库 name : 'fullName'
}, {
name : 'state'
} ]
});
store.loadData(myData);
var grid = new Ext.grid.GridPanel({
store : store,
columns : [ {
id : 'fullName',
header : "FullName",
width : 160,
sortable : true,
dataIndex : 'fullName'
}, {
header : "State",
width : 75,
sortable : true,
dataIndex : 'state'
} ],
stripeRows : true,
autoExpandColumn : 'fullName',
height : 350,
width : 600,
title : 'Array Grid',
bbar : new Ext.PagingToolbar({
store : store,
pageSize : 4,
displayInfo : true
}),
viewConfig : {
forceFit : true
}
});
You cannot at the same time use memory proxy
and autoLoad
config as well as store.load
. autoLoad
config and store.load
can only be used with proxies that are intended for actual loading of data like Ajax
proxy.
However, you can use Direct
proxy. In this case you will have to create your direct-function
which will play role of server-side
.
var myData = [
['J', 'MD'],
...
];
var myDirectfn = function(opts, fn, proxy){
var start = opts.start, end = opts.page*opts.limit;
var data = [];
if (end > myData.length)
end = myData.length;
for (var i = start; i < end; i++)
data.push(myData[i]);
fn(0, {status: true, result: data});
};
//Why am I doing this? I don't know, but otherwise store will throw exception
myDirectfn.directCfg={method : {}};
var store = new Ext.data.Store({
//totalProperty : 8,
pageSize: 4,
proxy: {
type: 'direct',
directFn: myDirectfn,
reader: {type: 'array'}
},
fields : [ {name : 'fullName'}, {name : 'state'} ]
});
And here is fiddle to play arround with.
UPDATE
For extjs3 Direct Proxy method would look like this:
var myDirectfn = function(opts, fn, proxy) {
var start = opts.start,
end = opts.limit+opts.start,
data = [];
if (end > myData.length) end = myData.length;
for (var i = start; i < end; i++)
data.push(myData[i]);
data.total = myData.length;
fn(data, {
status: true,
result: data
});
};
myDirectfn.directCfg = {
method: {len:1}
};
var store = new Ext.data.ArrayStore({
proxy: new Ext.data.DirectProxy({
directFn: myDirectfn
}),
fields: [{
name: 'fullName'},
{
name: 'state'}]
})
store.load({params: {start: 0, limit: 4}});
Here is demo. And also it appears that you can utilise memory proxy with load
ing by using this plugin
精彩评论