PDA

View Full Version : how to create mvc store multiple separate instances not sharing extraparams values.



maneljn
14 Jun 2012, 9:20 AM
i have this store in mvc structure



// Store para las aplicaciones definidas
Ext.define('esicontrol.store.aplicaciones', {
extend: 'Ext.data.Store',

model: 'esicontrol.model.aplicacion',
autoLoad: false,
remoteSort: true,
pageSize: 50,
proxy: {
type: 'direct',
paramAsHash: true,
extraParams: {
buscar: null
},
api: {
read: Ext.esinubeDirect.esicontrol_aplicaciones.getAplicacionesTodas
},
// Los datos llegan en json
reader: {
type: 'json',
root: 'data',
idProperty: 'apl_id',
totalProperty: 'total',
successProperty: 'success'
}
}

});


If i create multiple instances like this, it works fine, because in Storemanager, each instance is added separatedly.
But the problem is that the extraparams, is shared between all instances



store: Ext.create('esicontrol.store.aplicaciones', { id: Ext.id() } )

maneljn
22 Jun 2012, 6:47 AM
any idea about ?

maneljn
22 Jun 2012, 7:17 AM
I found a solution that works well

Define model like this


// Modelo de datos para las aplicaciones definidas
Ext.define('esinube.model.esicontrol.aplicacion', {
extend: 'Ext.data.Model',
fields: [
{ name: 'apl_id', type: 'integer' },
{ name: 'apl_guid', type: 'string' },
{ name: 'apl_nombre', type: 'string' },
{ name: 'apl_descripcion', type: 'string' },
{ name: 'apl_nombre_interno', type: 'string' },
{ name: 'apl_accdir_controller', type: 'string' },
{ name: 'apl_accdir_fn', type: 'string' },
{ name: 'apl_activo', type: 'boolean' },
{ name: 'apl_fechaalta', type: 'date', dateFormat: 'Y-m-d H:i:s' },
{ name: 'apl_fechamod', type: 'date', dateFormat: 'Y-m-d H:i:s' }
]
});


Define store like this


// Store para las aplicaciones definidas
Ext.define('esinube.store.esicontrol.aplicaciones', {
extend: 'Ext.data.Store',

requires: [
'esinube.model.esicontrol.aplicacion'
],

constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad: false,
model: 'esinube.model.esicontrol.aplicacion',
remoteSort: true,
pageSize: 50,
proxy: {
type: 'direct',
paramAsHash: true,
extraParams: {
buscar: null
},
api: {
read: Ext.esinubeDirect.esicontrol_aplicaciones.getAplicacionesTodas
},
reader: {
type: 'json',
root: 'data',
idProperty: 'apl_id',
totalProperty: 'total',
successProperty: 'success'
}
}
}, cfg)]);
}
});


Instantiate each store you want like this:


mystore = Ext.create('esinube.store.esicontrol.aplicaciones', {
storeId: Ext.id()
});

mystore2 = Ext.create('esinube.store.esicontrol.aplicaciones', {
storeId: Ext.id()
});


And that's the magic, if you put any value in mystore extraparams, if you like inside storemanager, you have to see that mystore2 doesn't inherit the extraparams values of mystore


mystore.getProxy().extraParams.buscar = "anything";
mygrid.paginacionGrid.moveFirst();

wemerson.januario
30 Dec 2013, 7:49 PM
How about when need to use proxy in model? I need to use proxy on models and having this same problem about extraParams