View Full Version : How to write store- and form data to database by one request

11 Apr 2013, 9:16 AM

i need to write data of a store and a form to database at one time. At serverside i want to run operations in context of transaction. Is it a good decision to use store.sync() and add form.getValues() as proxy params? How is it possible to call sync() twice, when store (grid) is untouched (form changes only)?

Or shall i use Ext.Ajax.request()? How to add store's records?

I could also submit the form and add store's record to formsubmit, but how?

11 Apr 2013, 6:03 PM
You could add your form's data as extra params in the writer of the proxy of your store and execute via store.sync(). Make sure the extra params are variables set but the current contents of the form.

You could also technically add the form data to your store as additional columns in your model. If this content is being seen by users, you can hide the columns and just send them across to the server.

I've yet to use a pure Ajax request outside of a store/proxy setup so would not be of much help here. Perhaps others in the forum could give you some tips using this approach


12 Apr 2013, 2:17 AM
It can be possible, that i need to submit the store with same records multiple times. (only detail data changes, form is detail data) --> is there a way to let sync() believe, that all records are new ones?

12 Apr 2013, 4:38 AM
You can set each record to dirty and I believe that the store will think that there is a change that needs to be synched. If you end up putting the form data in the model of the store, changing that data will make the record dirty automatically

14 Apr 2013, 3:46 AM
store.sync() seems to be a bad idea. one request per record.

I now using form.submit() and I add the store's data as param.

var data = [];
store.each(function(rec) {
var jsonData = "data=" + Ext.encode({records: data});

url: 'xyz.php',
params: jsonData,

at server-side I use json_decode() and go on with that object.

14 Apr 2013, 5:21 AM
I beleive your store.sync is sending one request per record because the store's proxy batchActions is set to false (just guessing here). If batchActions is set to true, it would send only one request altogether if all of your actions were updates.

In any case form.submit works as well if you want to control exactly what records in your store you want to send to the server. If that works for you, great! The store.sync() function, though, simplifies your code, where you dont have to iterate through each record in the store to get it to be sent to the server. The store know what records it needs to send to sync up.