PDA

View Full Version : Populate grid from DirectStore



randomY
11 Sep 2009, 9:54 AM
I've already read more that one thread on this same subject. Either they haven't helped or the person was just left unanswered.

I've been trying to populate a simple test grid using the Ext direct-pack download. Am running under ext ver 3.0.1, but same result under svn. My store looks like:



var reader = new Ext.data.JsonReader({
successProperty: 'success',
idProperty: 'id',
root: 'result',
fields: [
{name: 'id', type: 'int'},
{name: 'tag', type: 'string'},
{name: 'val', type: 'string'}
],
});

var store = new Ext.data.DirectStore({
reader: reader,
storeId: 'areastore-id',
autoLoad: true,
remoteSort: false,

api: {
read: IRIS.AreaSubstitutions.read,
create: IRIS.AreaSubstitutions.create,
destroy: IRIS.AreaSubstitutions.destroy,
update: IRIS.AreaSubstitutions.updat
},
});
Nothing special about that.
On the server I have classes/AreaSubstitutions.php:


class AreaSubstitutions {
/**
* @remotable
* @remoteName read
*/
public function read() {
$dbf = getenv('VI_DB');
$db = new SQLite3($dbf.'/Area_DEFAULT.sqlite');
$res = $db->query("SELECT * FROM area_substitutions");

while ($row = $res->fetchArray()) {
$arr[] = $row;
}

return $arr;
}

etc...

I assume my problem is how am not doing anything special other that just returning the array, but there are no examples to look at.

The post to the server looks like:


{
"action":"AreaSubstitutions",
"method":"read",
"data":null,
"type":"rpc",
"tid":2
}The return from the server:


{
"type":"rpc",
"tid":2,
"action":"AreaSubstitutions",
"method":"read",
"result":[
{"0":1,"id":1,"1":"GeneralHiPassFilter","tag":"GeneralHiPassFilter","2":"2,4","val":"2,4"},
{"0":2,"id":2,"1":"ChansPerStreamer","tag":"ChansPerStreamer","2":"324","val":"324"},
{"0":101,"id":101,"1":"MinDispRawData","tag":"MinDispRawData","2":"-2","val":"-2"},
{"0":102,"id":102,"1":"MaxDispRawData","tag":"MaxDispRawData","2":"2","val":"2"},
{"0":103,"id":103,"1":"MinDispRMSData","tag":"MinDispRMSData","2":"1","val":"1"},
{"0":104,"id":104,"1":"MaxDispRMSData","tag":"MaxDispRMSData","2":"40","val":"40"}
]
}
I realize that there is no 'success' property in this return.

This test is of a copy of a bit of an actual application which uses a normal Ext.data.Store with a JsonReader. That bit of code works fine and the result looks like:


{
success: 'true',
results:
[
{"0":1,"id":1,"1":"GeneralHiPassFilter","tag":"GeneralHiPassFilter","2":"2,4","val":"2,4"},
{"0":2,"id":2,"1":"ChansPerStreamer","tag":"ChansPerStreamer","2":"324","val":"324"},
{"0":101,"id":101,"1":"MinDispRawData","tag":"MinDispRawData","2":"-2","val":"-2"},
{"0":102,"id":102,"1":"MaxDispRawData","tag":"MaxDispRawData","2":"2","val":"2"},
{"0":103,"id":103,"1":"MinDispRMSData","tag":"MinDispRMSData","2":"1","val":"1"},
{"0":104,"id":104,"1":"MaxDispRMSData","tag":"MaxDispRMSData","2":"40","val":"40"}
]
}
Any insight would be appreciated.

randomY
11 Sep 2009, 10:31 AM
Some modications I made:


var reader = new Ext.data.JsonReader({
successProperty: 'result.success',
idProperty: 'id',
root: 'result.data',
fields: [
{name: 'id', type: 'int'},
{name: 'tag', type: 'string'},
{name: 'val', type: 'string'}
],
});

var store = new Ext.data.DirectStore({
storeId: 'areastore-id',
reader: reader,
autoLoad: true,
autoSave: true,
remoteSort: false,
paramsAsHash: true,

api: {
read: IRIS.AreaSubstitutions.read,
create: IRIS.AreaSubstitutions.create,
destroy: IRIS.AreaSubstitutions.destroy,
update: IRIS.AreaSubstitutions.update
}
});

public function read() {
//$a = '';
$dbf = getenv('VI_DB');
$db = new SQLite3($dbf.'/Area_DEFAULT.sqlite');
$res = $db->query("SELECT * FROM area_substitutions");

while ($row = $res->fetchArray(SQLITE3_ASSOC)) {
$foo[] = $row;
}

$bar = array(
'success' => 'true',
'data' => $foo
);

return $bar;
}
Result:


{
"type":"rpc",
"tid":3,
"action":"AreaSubstitutions",
"method":"read",
"result":{
"success":"true",
"data":[
{"id":1,"tag":"GeneralHiPassFilter","val":"2,4"},
{"id":2,"tag":"ChansPerStreamer","val":"324"},
{"id":101,"tag":"MinDispRawData","val":"-2"},
{"id":102,"tag":"MaxDispRawData","val":"2"},
{"id":103,"tag":"MinDispRMSData","val":"1"},
{"id":104,"tag":"MaxDispRMSData","val":"40"}
]
}
}
Doesn't populate the grid.

ThorstenSuckow
14 Sep 2009, 6:09 PM
Same problem here. I've been banging my head because of this. The problem is in the "doCall()" method of RemotingProvider: If you do not specify the "len" property for a method in your Remoting api configuration, things turn out ugly. Somehow the specified callback won't get called due to some magic that happens in this method.
So specify at least "len" with "1" or any other number.

Devs, please shed some light on this issue!




doCall : function(c, m, args){
var data = null, hs = args[m.len], scope = args[m.len+1];

if(m.len !== 0){
data = args.slice(0, m.len);
}

var t = new Ext.Direct.Transaction({
provider: this,
args: args,
action: c,
method: m.name,
data: data,
cb: scope && Ext.isFunction(hs) ? hs.createDelegate(scope) : hs
});

if(this.fireEvent('beforecall', this, t) !== false){
Ext.Direct.addTransaction(t);
this.queueTransaction(t);
this.fireEvent('call', this, t);
}
}



Edit:
Created an issue report: http://www.extjs.com/forum/showthread.php?p=386647#post386647