PDA

View Full Version : extjs 4.2 store.sync() don't refresh returned data anymore ?



maneljn
11 Apr 2013, 5:52 AM
With extjs 4.1.1.a when i sync() a store, and then in php i return json data of refreshed record, the model record and the grid is automatically refreshed.

Now i am upgrading to ext v4.2 and this doesn't work anymore.
I have not changed nothing in my source code

Is it normal ?

maneljn
11 Apr 2013, 6:18 AM
sorry i correct the question.

In this problem i do a model.save() (not a store.sync()) using direct proxy api update function
And the returned data looks like this:




{"type":"rpc","tid":10,"action":"esicontactos_contactos","method":"updateContacto","result":{"success":true,"data":[{"cto_id":"63","cto_guid":"5050a5317736a","cto_tipo":"E","cto_sexo":"","cto_nombre_propio":"","cto_apellidos":"","cto_nombre_fiscal":"ACME INC.","cto_nombre_com":"","cto_nif":"","cto_nacimiento":null,"cto_idioma":"es_ES","cto_observaciones":"observa\nPEPITOR\nMAR\u00cda\ndf \nvs\nvs\nfv s\nfv \nsfv\n sdfv\n sv\n sfv\ns df\nv sd\nfv s\nf s\nf sd\nfv sd\nf sd\nfv \n","cto_activo":"1","cto_usralta_id":"1","cto_fechaalta":"2012-09-12 17:07:29","cto_usrmod_id":"1","cto_fechamod":"2013-04-11 16:16:14","dir_id":"50","dir_guid":"5050a53177b63","dir_contacto_id":"63","dir_fiscal":"1","dir_alias":"","dir_via":"PL","dir_nom":"CREU DE LA M\u00c0","dir_num":"1","dir_esc":"2","dir_pis":"3","dir_pue":"4","dir_direc1":"PL CREU DE LA M\u00c0 1 2 3 4","dir_direc2":"","dir_pos":"08001","dir_pob":"BARCELONA","dir_pro":"","dir_pais_iso3":"ESP","dir_tel1":"","dir_tel2":"","dir_fax":"","dir_email":"","dir_web":"","dir_activo":"1","dir_usralta_id":"1","dir_fechaalta":"2012-09-12 17:07:29","dir_usrmod_id":"1","dir_fechamod":"2013-04-11 16:16:14","cto_edad":null,"cto_gruposcontactos_asignados":[0],"cto_esUsuario":"0","cto_usralta_nombre":"JU\u00c0REZ NICOLAU, MANEL","cto_usrmod_nombre":"JU\u00c0REZ NICOLAU, MANEL"}],"total":"1"}}




The model


//@charset UTF-8

// Modelo de datos para los contactos
Ext.define('esicontactos.model.contacto', {
extend: 'Ext.data.Model',

idProperty: 'cto_id',
fields: [
{ name: 'cto_id', type: 'integer' },
{ name: 'cto_guid', type: 'string' },
{ name: 'cto_tipo', type: 'string' },
{ name: 'cto_sexo', type: 'string' },
{ name: 'cto_nombre_propio', type: 'string' },
{ name: 'cto_apellidos', type: 'string' },
{ name: 'cto_nombre_fiscal', type: 'string' },
{ name: 'cto_nombre_com', type: 'string' },
{ name: 'cto_nif', type: 'string' },
{ name: 'cto_nacimiento', type: 'date', dateFormat: 'Y-m-d' },
{ name: 'cto_idioma', type: 'string' },
{ name: 'cto_edad', type: 'integer' },
{ name: 'cto_observaciones', type: 'string' },
{ name: 'cto_activo', type: 'boolean' },
{ name: 'cto_esUsuario', type: 'boolean', persist: false },

// Vienen y van los ids de grupos asisnados en un array de integers
{ name: 'cto_gruposcontactos_asignados', type: 'auto' },

// Direccion fiscal
{ name: 'dir_via', type: 'string' },
{ name: 'dir_nom', type: 'string' },
{ name: 'dir_num', type: 'integer' },
{ name: 'dir_esc', type: 'string' },
{ name: 'dir_pis', type: 'string' },
{ name: 'dir_pue', type: 'string' },
{ name: 'dir_direc1', type: 'string' },
{ name: 'dir_direc2', type: 'string' },
{ name: 'dir_pos', type: 'string' },
{ name: 'dir_pob', type: 'string' },
{ name: 'dir_pro', type: 'string' },
{ name: 'dir_pais_iso3', type: 'string' },
{ name: 'dir_tel1', type: 'string' },
{ name: 'dir_tel2', type: 'string' },
{ name: 'dir_fax', type: 'string' },
{ name: 'dir_email', type: 'string' },
{ name: 'dir_web', type: 'string' },

{ name: 'cto_usralta_id', type: 'integer', persist: false },
{ name: 'cto_fechaalta', type: 'date', dateFormat: 'Y-m-d H:i:s', persist: false },
{ name: 'cto_usrmod_id', type: 'integer', persist: false },
{ name: 'cto_fechamod', type: 'date', dateFormat: 'Y-m-d H:i:s' }, // Este campo se usará para el aviso de sobreescritura en concurrencia (2 usuarios grabando en el mismo registro a la vez)
{ name: 'cto_usralta_nombre', type: 'string', persist: false },
{ name: 'cto_usrmod_nombre', type: 'string', persist: false }
]

});



The store


Ext.define('esicontactos.store.contactos', {
extend: 'Ext.data.Store',

requires: [
'esicontactos.model.contacto'
],

constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad: false,
autoSync: false,
buffered: false,
model: 'esicontactos.model.contacto',
remoteSort: true,
remoteFilter: true,
pageSize: 50,
proxy: {
type: 'direct',
batchActions: false,
paramAsHash: true,
extraParams: {
buscar: null
},
api: {
read: Ext.esicontactosDirect.esicontactos_contactos.getContactos,
create: Ext.esicontactosDirect.esicontactos_contactos.createContacto,
update: Ext.esicontactosDirect.esicontactos_contactos.updateContacto,
destroy: Ext.esicontactosDirect.esicontactos_contactos.destroyContacto
},
reader: {
type: 'json',
root: 'data',
idProperty: 'cto_id',
totalProperty: 'total',
successProperty: 'success',
messageProperty : 'message'
}
}
}, cfg)]);
}


});



The returned data is not refreshed in the model record.

alsid
31 May 2013, 9:53 AM
Can you show the code which inserts new record into the store before calling save() or sync() functions?

I had similar issue with ExtJs 4.2. I was getting an empty record with reader, modifying it (filling all the fields) and than calling sync() method expecting that fields which were not filled would be updated. Particularly I was expecting that ID field will be populated with value generated by server. At least it was working like that with prior versions of ExtJs.

With ExtJs 4.2 I've got a problem. Returned data was OK but id field of the record wasn't refreshed. The problem appeared to be with the sequence of sync operations which was generated by proxy object. In my scenario proxy was generating an update operation which assumes that record has normal id. I solved my issue by setting id property with setId() method of the model to null or empty value. After that proxy started generating insert operation which was right. I know that the whole thing about such way of inserting record is not good but the problem was not in my code so I decided not to change it a lot.

I think your problem is also related to Ids.
Hope it will help.

ejerrywest
14 Jun 2013, 9:03 AM
I had the same problem, that appeared in 4.2.

Found that I was calling "store.commitChanges" before I was calling "store.sync". When I took that out it handled the problem

beticocorzo
29 Apr 2014, 5:46 AM
Hi, did you resolve the issue? because i'm in the same problem my store have autosync=true but when i add a new record my grid does not refresh.

Working at the same time with extjs 4.1.1 with another project all works perfectly, but extjs 4.2.1 seems to have a bug.

maneljn
29 Apr 2014, 6:28 AM
I could not solve it.
I continue using v4.1.1
If you have good news for me, it would be appreciated. ;-)

Manel

beticocorzo
29 Apr 2014, 7:24 AM
I could not solve it.
I continue using v4.1.1
If you have good news for me, it would be appreciated. ;-)

Manel

Problem is, when the data have to get back to extjs, always the id comes empty, i set in the reader idProperty=idsocio and anything seems works, i do not wanna downgrade to 4.1.1 :(( , if i know how to resolve this case, you gonna be the first to know about how to fix this issue.

maneljn
29 Apr 2014, 7:52 AM
Can you post your piece of code ?

beticocorzo
29 Apr 2014, 8:20 AM
Can you post your piece of code ?

Sure:


Ext.define('siccar.store.storeListaAcreditados', {
extend: 'Ext.data.Store',


requires: [
'siccar.model.modelListaAcreditados',
'Ext.data.proxy.Ajax',
'Ext.data.reader.Json',
'Ext.data.writer.Json'
],


constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoSave: true,
autoLoad: false,
autoSync: true,
model: 'siccar.model.modelListaAcreditados',
storeId: 'storeListaAcreditados',
proxy: {
type: 'ajax',
afterRequest: function(request, success) {
if (request.action == 'create')
{


var jsonMsg = (request.operation.params.data.idsocio);
var vMsg=jsonMsg.msg; //msg :viene del Archivo PHP
Ext.Msg.alert('Actualizado',vMsg);


}
},
actionMethods: {
read: 'POST'
},
api: {
create: 'controller_acreditados/insertAcreditados',
read: 'controller_acreditados/readListaAcreditados',
update: 'controller_acreditados/updateAcreditados',
destroy: 'controller_acreditados/deleteAcreditados'
},
reader: {
type: 'json',
idProperty: 'idsocio',
root: 'data'
},
writer: {
type: 'json',
dateFormat: 'Y-m-d',
encode: true,
root: 'data'
}
}
}, cfg)]);
}
});



greetings

icebergdelphi
29 Apr 2014, 2:30 PM
Did you check your idPropierty in your reader? this should be the same as the result or your column id from your database, (in your case idsocio), another problem is when the data result some times comes with error, i mean, check your json insert result with firebug if you have some bad insert or something else, i was with the same problem and i realized that the problem was the invalid JSON String or etc. :D

beticocorzo
29 Apr 2014, 2:57 PM
Well in my case,yep you are right icebergdelphi, i was checking with firefug and the problem seen to be a field date of my form and if i let this field empty and click save, the extjs raw grid appears with phantom record, and in my json result : Ext.Error: You're trying to decode an invalid JSON String, but if i do not let the field date empty the refresh grid after insert works perfectly. Thanks a lot.:D

beticocorzo
29 Apr 2014, 3:16 PM
Can you post your piece of code ?

Hi again Maneljn check my answer , a user named icebergdelphi exposed a solution, my problem was in my insert function in the server side, i wrote a named field with a wrong name. i mean in my database (fechanacimiento) and in my insert sql code i wrote( fechaNacimiento), you have check everything.