PDA

View Full Version : [3.0 RC1] DirectStore



bas_denis
17 Apr 2009, 4:06 AM
any working DirectStore example?

me don't get it,
help appreciated (if using svn version plz mention)
backend and Provider is not needed / not in detail, those are working fine
(used Ext.Direct Example and added a getData method which gives some Array of Objects Result)

kind regards

my try:

post:

{"action":"TestAction","method":"getData","data":null,"type":"rpc","tid":2}
response:

{"type":"rpc","tid":2,"action":"TestAction","method":"getData",
"result":[
{"id":1,"value":"Value 1"},
{"id":2,"value":"Value 1"},
{"id":3,"value":"Value 2"}
]}
testcase:

Ext.onReady(function()
{
Ext.Direct.addProvider({
url : "php/router.php",
type : "remoting",
id : 'remote-provider',
actions : {
TestAction : [
{
name : "getData",
len : 0
}
]
}
});

var getData = new Ext.Button({
text : 'getData',
handler : function()
{
TestAction.getData(function(result, e)
{
console.debug(result)
});
}
});

var store = new Ext.data.DirectStore({
autoLoad : true,
// directFn isn't recognized by proxy, used api:load instead
api : {
load : TestAction.getData
},
root : 'result',
paramsAsHash : false,
fields : [
'id',
'value'
],
listeners : {
load : function()
{
console.info('load', this, arguments)
},
loadexception : function()
{
console.warn('loadexception', this, arguments)
},
scope : this
}
});

var grid = new Ext.grid.GridPanel({
store : store,
columns : [
{
id : 'id',
header : 'id',
width : 200,
dataIndex : 'id'
},
{
header : 'value',
width : 120,
dataIndex : 'value'
}
],
viewConfig : {
forceFit : true
},
sm : new Ext.grid.RowSelectionModel({
singleSelect : true
})
});

var p = new Ext.Panel({
title : 'Remote Call Grid',
width : 600,
height : 300,
layout : 'fit',
items : [
grid
],
bbar : [
getData
]
}).render(Ext.getBody());

});

added bugnote: [3.0 RC1] Ext.data.DirectProxy incomplete ? (http://extjs.com/forum/showthread.php?t=65919)

bas_denis
18 Apr 2009, 4:40 AM
for sure DirectProxy seems incomplete.

not using the directFn on store config,
instead using api.load, causes DirectProxy.doRequest to add the params ({xaction:'load'}) as a first argument,
so it mismatches the Provider methods arguments and with it the arguments callback position

as a unpretty workaround for the above code it should do setting the Providers method arguments len to 1 and removing the root property

if DirectProxy working as intended, it may look something like this: (for the above code)

[ ... ]
var store = new Ext.data.DirectStore({
autoLoad : true,
directFn : TestAction.getData,
//root : 'result',
fields : [
'id',
'value'
]
});
[ ... ]

Artistan
19 May 2009, 2:51 PM
I am trying the directFn and it is adding 'xaction' => 'load' to the 'data' passed.
POST


{"action":"ExtDirect_Tickets","method":"get","data":["id","ASC","1","10"],"type":"rpc","tid":2}


How do I get it to load without that, and pass parameters to the function?

UPDATE::
when I added baseParams, paramsNames it works,
but that locks it down the the baseParams.




Ext.ns('Ext.BENINT'); Ext.BENINT.APIDesc = {"url":"router\/","type":"remoting","actions":{"ExtDirect_Tickets":[{"name":"get","len":2},{"name":"add","len":2,"formHandler":true},{"name":"save","len":2,"formHandler":true},{"name":"delete","len":2,"formHandler":true},{"name":"list","len":1,"serverMethod":"example"},{"name":"doEcho","len":1},{"name":"multiply","len":1}]},"namespace":"Ext.BENINT"};






var store = new Ext.data.DirectStore({
api: {
load: Ext.BENINT.ExtDirect_Tickets.get,
create: Ext.BENINT.ExtDirect_Tickets.add,
save: Ext.BENINT.ExtDirect_Tickets.save,
destroy: Ext.BENINT.ExtDirect_Tickets.delete
},
paramOrder: ['sort','dir','start','limit'],
autoLoad : true,
storeId:'open-tickets',
root: 'list',
paramsNames: {
start : "start", // The parameter name which specifies the start row
limit : "limit", // The parameter name which specifies number of rows to return
sort : "sort", // The parameter name which specifies the column to sort on
dir : "dir" // The parameter name which specifies the sort direction
},
remoteSort: true,
baseParams: {
start : "1",
limit : "10",
sort : "id",
dir : "ASC"
},
idProperty: 'id',
fields: [
{
name: 'id',
type: 'int'
},
'value'
],
listeners : {
load : function()
{
console.info('load', this, arguments)
},
loadexception : function()
{
console.warn('loadexception', this, arguments)
},
update : function()
{
/*
this.commitChanges
Commit all Records with outstanding changes.
To handle updates for changes, subscribe to the Store's update event,
and perform updating when the third parameter is Ext.data.Record.COMMIT.
*/
console.warn('loadexception', this, arguments)
},
scope : this
}
/*baseParams*/
/*writer*/
});

// create the Grid
var grid = new Ext.grid.EditorGridPanel({
store: store,
colModel: new Ext.grid.ColumnModel({
columns: [
{id:'ticket_id', header: "ID", width: 30, dataIndex: 'id'},
{id:'ticket_value', header: "Value", dataIndex: 'value'}
/*{header: "Change", renderer: change, dataIndex: 'change'}*/
],
defaults: {
sortable: true,
width: 75
}
}),
autoExpandColumn: 'ticket_value', // match the id specified in the column model
height:350,
width:600,
/*title:'Array Grid',*/
tbar: [{
text: 'Add Record',
handler : function(){
/*****************
Need to find how to add to db
*****************/
var defaultData = {
id: '-',
value: '1'
};
var recId = 3; // provide unique id
var p = new store.recordType(defaultData, recId); // create new record
grid.stopEditing();
store.insert(0, p); // add new record to the store
grid.startEditing(0, 0);
}
}]
});

var p = new Ext.Panel({
title : 'Remote Call Grid',
width : 600,
height : 300,
layout : 'fit',
items : [
grid
],
bbar : [
getData
]
}).render(Ext.getBody());



Response


{"type":"rpc","tid":2,"action":"ExtDirect_Tickets","method":"get","result":{"list":[{"id":1,"value":"'id'"
},{"id":2,"value":"foo"},{"id":3,"value":"foo"},{"id":4,"value":"foo"},{"id":5,"value":"foo"},{"id":6
,"value":"foo"},{"id":7,"value":"foo"}],"count":7}}