I use dwrproxy.js from https://code.google.com/p/extjs4dwr and I create a grid with store
Ext.onReady(function() {
Ext.define('Record', {
extend: 'Ext.data.Model',
fields : [
{name: 'clientName'},
{name: 'type'}
],
proxy : {
type: 'dwr',
dwrFunction : Manager.getList,
reader : {
type: 'json',
root: 'data',
totalProperty: 'count'
}
}
})
var store = Ext.create('Ext.data.Store', {
requires : ['Ext.ux.DwrProxy'],
model: 'Record'
});
var grid = new Ext.grid.GridPanel({
store : store,
columns: [
{header: "clientName", width: 260, sortable: true, dataIndex: 'clientName'},
{header: "type", width: 260, sortable: true, dataIndex: 'type'}
],
title:'Test view',
renderTo: 'container'
});
store.load();
});
Manager.getList
looks
Manager.getList = function(p0, p1, callback) {
dwr.engine._execute(Manager._path, 'Manager', 'getList', p0, p1, callback);
}
And I receive data in dwr
throw 'allowScriptTagRemoting is false.';
//#DWR-INSERT
//#DWR-REPLY
var s0=[];var s2={};var s3={};
s2.clientName='Client1';s2.type='Type1';
s3.clientName='Client2';s3.type='Type2';
s1.descendingOrder=true;s1.pageNo=null;s1.pageSize=1;s1.sortField="lastEditTime";
dwr.engine._remoteHandleCallback('1','0',{data:s0,dataSize:2,fromIndex:0,fromIndexDisp:1,gridState:s1,metaData:null,moreData:null,pageNo:0,pageNumber:1});
Everything look good, but grid is still have a 'loading' status and there are no view. Please, help.
I don't know anything about DWR, but by mocking your code we can see that the callback is passed as the first argument to your getList()
method, but it expects it as the third argument.
The position of the callback argument will in fact depend on the dwrParams
config option of the proxy:
// adding parameters if there are defined any in proxy
// configuration
if (typeof (me.dwrParams) === 'object') {
dwrParams = dwrParams.concat(me.dwrParams);
}
So, what you need to do is configure your params in the proxy:
proxy : {
type: 'dwr',
dwrFunction : Manager.getList,
// use params that are sensible for your function
dwrParams: [1,2],
// ... your reader config
}
Or I guess that would probably makes more sense to set these before loading your store instead:
store.proxy.dwrParams = [1,2];
store.load();
If you want to avoid this hackish way, you can override the proxy's code. For example, if you replace these lines (starting line 71 in my version):
// adding parameters if there are defined any in proxy
// configuration
if (typeof (me.dwrParams) === 'object') {
dwrParams = dwrParams.concat(me.dwrParams);
}
By these:
// adding parameters if there are defined any in proxy
// configuration
var loadParams = operation.dwrParams || me.dwrParams;
if (typeof (loadParams) === 'object') {
dwrParams = dwrParams.concat(loadParams);
}
You could then load your store in a clean way:
store.load({
dwrParams: [3,4]
});
As a side note, I saw an error in the DwrProxy's code. A bit further in the same function, there is this code that uses a dwrParams0
variable that does not exist:
case 'read':
me.dwrFunction.read.apply(null, dwrParams0);
break;
I guess the author probably meant dwrParams[0]
. You may want to fix this if you ever need to use different functions for the different CRUD operation as in the DwrProxy example.