-
14 Feb 2011 2:51 AM #1
Posta store to server
Posta store to server
Hi,
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.
Regards,Code:demoStore = new Ext.data.Store({ id :'demoStore', data: [ ["A","216","java",], ["B","209","php",], ["C","10","dotnet"] ], reader: new Ext.data.ArrayReader({id:'id'}, [ 'name', 'id', language' ]) });
Saurabh
-
14 Feb 2011 1:01 PM #2
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 #3
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.
Regards,
Saurabh Agarwal
-
15 Feb 2011 6:23 AM #4
I suppose you could have a "save" button in your toolbar with the following handler:
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.PHP Code:var dataArray = [];
function getData(record) { dataArray.push(record.data); }
myStore.each(getData);
Ext.Ajax.request({
url: 'doSomething.php'
params: {
data: Ext.encode(dataArray)
},
success: function(response, options) {}
});
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).
Similar Threads
-
Ext.data.Store server communication
By triple in forum Ext 3.x: Help & DiscussionReplies: 1Last Post: 30 Mar 2010, 2:10 PM -
Grid Extension columns and store from server from server
By qulys in forum Ext 3.x: Help & DiscussionReplies: 0Last Post: 23 Nov 2009, 2:09 AM -
Stop the server request from store ?
By ritesh.kapse in forum Ext 2.x: Help & DiscussionReplies: 6Last Post: 9 Sep 2008, 7:08 AM -
Persist Store to server?
By deitch in forum Ext 1.x: Help & DiscussionReplies: 7Last Post: 18 Oct 2007, 6:16 AM -
Saving data from a store to server
By marco.braga in forum Ext 1.x: Help & DiscussionReplies: 2Last Post: 3 Sep 2007, 7:02 AM


Reply With Quote