PDA

View Full Version : Writer Example



alconeijr
14 Mar 2010, 7:40 AM
Hello!

The latest Extjs version is introducing a feature that seems a bug. It can be simulated in the example http://www.extjs.com/deploy/dev/examples/writer/writer.html.
By adding a new record and save, the program is not sending the identifier of the record to the server. If the User change ten records for example and save the grid, how will I identify the records when they returned from the server?

Version 3.0.0 post:
data ( "first": "1", "last": "1", "email": "[email protected]", "id": "ext-record-1")

Version 3.1.1 post:
data ( "first": "1", "last": "1", "email": "[email protected]")

tonedeaf
14 Mar 2010, 11:23 AM
ExtJS expects you to provide the new ID of the record in the JSON response of the 'create' request.

I was having a similar issue where I had the same function for editing and creating a new record on the server. And to identify the new records I wanted to send the Store's "phantom" ID in the JSON request.

You can use this override, if you really want to send the Store's phantom ids to server:



/* Send the ext autogenerated ids to server on 'create' actions */
Ext.override(Ext.data.DataWriter, {
toHash : function(rec, config) {
var map = rec.fields.map,
data = {},
raw = (this.writeAllFields === false && rec.phantom === false) ? rec.getChanges() : rec.data,
m;
Ext.iterate(raw, function(prop, value){
if((m = map[prop])){
data[m.mapping ? m.mapping : m.name] = value;
}
});
data[this.meta.idProperty] = rec.id
return data;
}
});

alconeijr
16 Mar 2010, 2:34 PM
Thanks tonedeaf. It's worked fine!

cdomigan
10 Sep 2010, 8:32 PM
ExtJS expects you to provide the new ID of the record in the JSON response of the 'create' request.

Does anyone know where this is documented?