-
13 Jun 2010 2:31 PM #1
directStore with a JsonWriter sends no data with autoSave: true
directStore with a JsonWriter sends no data with autoSave: true
I have a directStore hooked up to a list and an edit form. It reads the data from the backend correctly, but when it saves, the data field is null. If I call store.save(), then it send the data for ALL rows, not just the ones that have changed. Here is my store setup:
Here is what it sends when I call:Code:skillStore = Ext.extend(Ext.data.DirectStore, { constructor: function (config) { var params = { autoLoad: true, autoSave: true, paramsAsHash: false, totalProperty: 'count', root: 'result', paramsAsHash: false, api: { //create: CRUD.create, read: orbital.Skill.read, update: orbital.Skill.update, //destroy: CRUD.destroy }, // I don't know why the writer does not get auto created like the reader writer: new Ext.data.JsonWriter( { returnJson: true, writeAllFields: true }), storeId: 'skill', fields: [ {name:'id', type: 'number'}, {name:'name', type: 'string'}, {name:'default_attribute', type: 'string'}, {name:'description', type: 'string'}, {name:'type', type: 'string'} ], }; config = Ext.apply (params, config); skillStore.superclass.constructor.call(this, config); } });Code:this.getForm().updateRecord(this.record);
any suggestions? what am I missing?Code:{"action":"Skill","method":"update","data":null,"type":"rpc","tid":3}
It's taken me a while to get here, but it seems so close.
--
Chris Bare
-
13 Jun 2010 10:16 PM #2Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 40
You need to configure your writer with encode:false.
-
14 Jun 2010 9:44 AM #3
I tried adding encode: false to the writer, but I still get the same "data":null sent to the backend.
-
14 Jun 2010 11:05 AM #4
actually I do see one difference. it says "result": null, which is the value I set in the DirectStore for root:
I see the updated value displayed in my grid, but is it possible that the store is not seeing the updated record? Here's what my form save does:
this.getForm().updateRecord(this.record);
which comes from the list via:
var rec = this.list.getSelectionModel().getSelected();
this.form.loadRecord(rec);
-
15 Jun 2010 3:27 PM #5
ok, I built a cut-down test case and it is still not working. I am using version 3.2.1. Here's my test case:
and here's what it sends when you press the modify button:Code:<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" type="text/css" href="ext/resources/css/ext-all.css"> <link rel="stylesheet" type="text/css" href="css/orbital.css"> </head> <body> <script type="text/javascript" src="ext/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="ext/ext-all-debug.js"></script> <script type="text/javascript" src="php/api.php"></script> <script type="text/javascript"> // Path to the blank image must point to a valid location on your server Ext.BLANK_IMAGE_URL = 'ext/resources/images/default/s.gif'; function modify () { var rec = list.getSelectionModel().getSelected(); rec.set ("description", "value"); store.save (); } orbital.API.maxRetries = 0; Ext.Direct.addProvider(orbital.API); store = new Ext.data.DirectStore ( { autoLoad: true, autoSave: false, root: 'result', api: { //create: CRUD.create, read: orbital.Skill.read, update: orbital.Skill.update, //destroy: CRUD.destroy }, // I don't know why the writer does not get auto created writer: new Ext.data.JsonWriter( { encode: false, writeAllFields: true }), fields: [ {name:'id', type: 'number'}, {name:'name', type: 'string'}, {name:'default_attribute', type: 'string'}, {name:'description', type: 'string'}, {name:'type', type: 'string'} ], }); list = new Ext.grid.GridPanel ( { region: 'center', store: store, columns: [ {header: 'ID', sortable: true, dataIndex: 'id'}, {header: 'Name', sortable: true, dataIndex: 'name'}, {header: 'Default Attribute', sortable: true, dataIndex: 'default_attribute'}, {id: 'description', header: 'Description', sortable: true, dataIndex: 'description'}, {header: 'Type', sortable: true, dataIndex: 'type'} ] }); button = new Ext.Button ( { region: 'south', text: "modify" }); button.on ('click', modify); function main () { viewport = new Ext.Viewport( { layout: 'border', items: [ list, button ] }); } // Main application entry point Ext.onReady( main ); </script> </body> </html>
I tried tracing the save function and I saw writer.json had the updated record, but I got lost in all the layers of callbacks etc.Code:{"action":"Skill","method":"update","data":null,"type":"rpc","tid":3}
what am I missing?
--
Chris Bare
-
1 Apr 2011 3:51 AM #6
Hi, I have the same problem. Have you found a solution to this?
Thanks
-
1 Apr 2011 7:19 AM #7
It's been a while, but I *think* my problem was that my backend function was declared with no parameters. I just stubbed it out, thinking I would finish it once I got the javascript side working. Well, since ext direct knows the function signature, it takes that into account and doesn't send anything if your function doesn't take any parameters.
-
14 Aug 2011 8:40 AM #8
You just saved me a whole load of time.
I was also trying to get it to work, thinking I'll just create a method stub (not thinking to add any arguments to the method). Added an argument to the method and BINGO - data sent!
Thanks!
Similar Threads
-
Race Condition - remove several records on a store with batch: false, autoSave: true
By chbfiv in forum Ext 3.x: Help & DiscussionReplies: 5Last Post: 2 May 2011, 2:39 PM -
Store with autoSave:true doesn't auto-save
By js_coder in forum Ext 3.x: Help & DiscussionReplies: 0Last Post: 11 Jan 2010, 12:17 PM -
dropping the root "data" element for jsonwriter with restful data store
By jkt in forum Ext 3.x: Help & DiscussionReplies: 2Last Post: 29 Nov 2009, 8:47 AM -
Tabpanel sends only data from active panel?
By Dumas in forum Ext 2.x: Help & DiscussionReplies: 1Last Post: 26 Mar 2009, 10:39 AM


Reply With Quote