View Full Version : Posta store to server

14 Feb 2011, 2:51 AM

We can use json objects to send the data to the client side using post or get method. That works perfectly cool. My concern is pther way round.
Let say I have a data store and i want to send this data store to the server then what is the best approach to do that. Further do extjs provide any method for this.

demoStore = new Ext.data.Store({
id :'demoStore',
data: [
reader: new Ext.data.ArrayReader({id:'id'}, [


14 Feb 2011, 1:01 PM
I probably wouldn't attempt to batch update all records in a database - I'd probably just use the "add" or "update" events on the Store() object, sending the data for each record that gets added/edited as separate AJAX requests.

15 Feb 2011, 2:34 AM
Hi arthur,

In scenarios, yes you are right, but my requirement says that all of the data is to be updated as a whole or nothing is to be updated, and hence i am maintaning the data store on the client side. Now since i am successfull in maintaining the data store throughout the process i do not want to convert it to some other format set it to some hidden field(or any other variable) and then send it across to server. Rather i am looking for a mechanism in which i can send the complete data store as it is, and will parse it as we do with the json stores.

I hope you got my point.

Saurabh Agarwal

15 Feb 2011, 6:23 AM
I suppose you could have a "save" button in your toolbar with the following handler:

var dataArray = [];

function getData(record) { dataArray.push(record.data); }


url: 'doSomething.php'
params: {
data: Ext.encode(dataArray)
success: function(response, options) {}

Basically, you just need to serialize each of the records in your store and send to the server. You could implement that in a number of ways, but I'd probably use the method above unless someone has a better implementation.

Alternatively, you could use the save() method on the data store - which saves all *pending* changes to the store. Latching onto the "save" event, you could launch an AJAX call to the server containing only the records that have changed. The handler would be similar to what I described above, but only looping over the records with pending changes (not necessarily ALL records in the store).