PDA

View Full Version : ExtraParams - Store Create



alain.buetler
17 Mar 2014, 5:54 AM
Is there an opportunity to set an extraParameter on the event 'beforesync' on a direct store, when I create a new record over the Grid Editing Plugin. The extraParameter is needed in a mysql statement afterwards.

Gary Schlosberg
19 Mar 2014, 8:35 AM
You should be able to listen to beforesync and pass extraParams. If you are having trouble, please post your code.

alain.buetler
21 Mar 2014, 2:28 AM
Ext.define('eKabu.store.Kostentraeger', {
extend: 'Ext.data.Store',


requires: [
'eKabu.model.Kostentraeger',
'eKabu.DirectAPI',
'Ext.data.proxy.Direct',
'Ext.data.reader.Json',
'Ext.data.writer.Json'
],


constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad: true,
model: 'eKabu.model.Kostentraeger',
storeId: 'Kostentraeger',
proxy: {
type: 'direct',
api: {
create: 'Kostentraeger.create',
read: 'Kostentraeger.read',
update: 'Kostentraeger.update',
destroy: 'Kostentraeger.delete'
},
extraParams: {
buchungsjahr: buchungsjahr_id
},
reader: {
type: 'json',
root: 'data'
},
writer: {
type: 'json'
}
},
listeners: {
beforesync: {
fn: me.onDirectstoreBeforeSync,
scope: me
}
}
}, cfg)]);
},


onDirectstoreBeforeSync: function(options, eOpts) {
var controller = eKabu.app.getController('Main');
controller.getKostentraegerStore().getProxy().setExtraParams(
{
'buchungsjahr': buchungsjahr_id
}
);
}


});

alain.buetler
16 Apr 2014, 11:04 PM
It doesn't work this way.. any solutions?

Gary Schlosberg
23 Apr 2014, 9:57 AM
Looks like extraParams are included only for read requests:
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.proxy.Direct-cfg-extraParams

I did find a feature request (EXTJS-9987) to optionally have them for other requests, but it hasn't been implemented.

jeffland
22 May 2014, 8:22 AM
I needed different extraParams in a writer than those in the general proxy (which are used for reading and writing), and defined an extraParams object in the proxy writer:


proxy: {
type : 'ajax',
...
extraParams: {
'cmd' : 'DispatcherGantt',
'objName' : 'tablePreamps',
'fntd' : '../MxrPre/data/TableDefs.php'
},
...
writer : {
type : 'json',
root : 'data',
extraParams: {
'objName' : 'tablePreampsWrite'
},
encode : true,
writeAllFields : false,
allowSingle : false,
writeRecordId : true
} // eo writer
} // eo proxy


Then included a test for those in my general updateStore routine in the model (you could put this test in several other routines):



updateStore : function(argStore, argRecModified, me, isNewRec) {
var recModified,
proxy = argStore.proxy,
paramsWriter = proxy.writer.extraParams;

isNewRec = isNewRec || false;

// set any special params specified in the writer
if (paramsWriter) {
Ext.Object.each(paramsWriter, function(key, value, oObject) {
proxy.setExtraParam(key, value);
});
}
...

and that works.