-
3 Oct 2006 1:39 PM #1
onCellUpdated and sending updates back to the server
onCellUpdated and sending updates back to the server
I'm having a bit of confusion about posting data back from the editable grid to my server.
I undestand that updating any of the cells fires the onCellUpdated event and it also updates the XMLDocument in the Document Model. However, I'm having difficulty figuring out the proper way to grab the updated data and post it back to the server.
I'm creating a Data Model with a schema like so:
This loads up the xml for my grid and displays the grid just fine. Now I want to save changes back to the db (saveContacts.cfm or some such). I think I just need a decent example of adding the listener in the proper place and doing an asynchronous post back.Code:var schema = { tagName: 'contact', id: 'id', fields: ['first_name', 'last_name', 'phone_home', 'phone_mobile', 'email'] }; dataModel = new YAHOO.ext.grid.XMLDataModel(schema); dataModel.setDefaultSort(colModel, 1, "DESC"); grid = new YAHOO.ext.grid.EditorGrid('editor-grid', dataModel, colModel); grid.render(); dataModel.load('/loadContacts.cfm'); }
Also, what would be best practice here, sending back the xml tree on every change or just sending back a single contact record? I would assume that it would be better to send back a single record, but I'm not sure how I would do that in this case.
Thanks in advance and kudos to Jack for putting together some awesome code that is teaching me a lot.
-
3 Oct 2006 8:19 PM #2
In my setup, I add a save button to the toolbar to save changes and post the xml document with edits back to the server. In some instances this may not be the best solution.
You can also do incremental saving as you hinted. The main issue here is manually implementing a buffer so every edit of every cell isn't causing an http call. Do it right can be rather involved.
Here's an example of what a saving routine might look like. It assumes dataModel is in scope and you have two functions handleSuccess and handleFailure to notify the user.
Code:function onSaveClick(e){ var xml = dataModel.getDocument(); var cb = {success: handleSuccess, failure: handleFailure} YAHOO.util.Connect.asyncRequest('POST', 'save.php', cb, xml); }
-
3 Oct 2006 11:20 PM #3
The way I update the server on significant events is using DWR.
If you have a Java backend, I highly recommend it.
I save column hide/resize events using DWR. I also have a custom DataModel and ColumnModel which pull their data using DWR.
http://getahead.ltd.uk/dwr/
-
4 Oct 2006 11:52 PM #4
Another Way
Another Way
An even better way would probably be to update the dataset when the "cursor" is moved via cursorChange. (just set some flag to know when data for that row had changed)
Similar Threads
-
Help: Sending Ext.tree data back to server (ColdFusion)
By MBragg in forum Ext 1.x: Help & DiscussionReplies: 2Last Post: 16 Aug 2007, 7:09 AM -
Error sending xml from grid to Server?
By franklt69 in forum Ext 1.x: Help & DiscussionReplies: 0Last Post: 21 Feb 2007, 1:37 PM -
onCellUpdated index
By pomata in forum Ext 1.x: Help & DiscussionReplies: 1Last Post: 16 Jan 2007, 12:14 PM -
Tree drag drop server updates
By seldon in forum Ext 1.x: Help & DiscussionReplies: 0Last Post: 13 Jan 2007, 5:30 AM -
Sending multiple tree node values to server.
By rahulmca1@gmail.com in forum Ext 1.x: Help & DiscussionReplies: 2Last Post: 10 Jan 2007, 12:22 AM


Reply With Quote