PDA

View Full Version : [3.0] Ext.data.store DataWriter ¿can I send one request when I add some records?



juanramoney
16 Apr 2009, 8:47 AM
When I add some records to a store and use commitChanges or save, it sends one request to the server for each record, ¿Is there any way to do it in one request?

thanks

17 Apr 2009, 4:16 AM
I have not really worked with writer yet, so I don't know if there is a config option.

I know that Direct does this.

shibubh
17 Apr 2009, 5:45 AM
yes you can do this

store has batchSave config option
code snipped from the writer example


var store = new Ext.data.Store({
id: 'user',
root: 'records',
proxy: proxy,
reader: reader,
writer: writer, // <-- plug a DataWriter into the store just as you would a Reader
paramsAsHash: true,
batchSave: true//
});


and the use

store.save();


to save

juanramoney
17 Apr 2009, 6:18 AM
the API says:

batchSave : Boolean

Defaults to false, which requires manually calling save to send all modifiedRecords to the server. Specify true for the store to automatically save records to the server when a record changes.

The problem is when I add for example 2 records and save, I expect it sends an array with the changes but it sends 2 requests. I attached and image with what shows firebug.

thanks

tryanDLS
17 Apr 2009, 8:10 AM
This functionality was demoed at the conf, so it may be that it was fixed post-RC1. Can you post a testcase?

juanramoney
17 Apr 2009, 9:06 AM
A simple test:


Ext.onReady(function() {
/*record*/
var rProf = Ext.data.Record.create(['id', 'Nombre', 'Apellidos', 'Correo']);

/*store*/
var lProf = new Ext.data.Store({
root: 'records',
proxy: new Ext.data.HttpProxy({
prettyUrls: false,
url: 'datos.php?op=mprof'
}),
reader: new Ext.data.JsonReader({
totalProperty: 'total',
successProperty: 'success',
idProperty: 'id',
root: 'data'
},
rProf),
writer: new Ext.data.JsonWriter({
returnJson: true,
writeAllFields: false
}),
paramsAsHash: true,
batchSave: false
});
/*new records*/
var nr = new rProf({
Nombre: 'test1',
Apellidos: 'Atest1'
});

var nr2 = new rProf({
Nombre: 'test2',
Apellidos: 'Atest2'
});

/*add records*/
lProf.add(nr);
lProf.add(nr2);
/*save changes*/
lProf.save();
});

And what shows firebug.

thanks

mjlecomte
17 Apr 2009, 9:13 AM
I'm just poking my nose in here. But it says batchSave. The api actions are different aren't they? So you're looking for something like batchCreate it seems.

mjlecomte
17 Apr 2009, 9:14 AM
Edit: I wasn't at the conference so I don't really know what I'm talking about...

mjlecomte
17 Apr 2009, 9:49 AM
Looking at the source it appears the create action is set up to fire the requests individually, not as an array.

shibubh
17 Apr 2009, 6:23 PM
A simple test:



paramsAsHash: true,
batchSave: false



And what shows firebug.

thanks


change batchSave:true and check the fireBug response

juanramoney
19 Apr 2009, 2:03 AM
change batchSave:true and check the fireBug response

It shows the same behaviour.

shibubh
19 Apr 2009, 2:35 AM
ok i sorry. what i found that batchsaves only apply for the updating the record.