PDA

View Full Version : How do I define a JsonWriter for a JsonStore that was created by the Designer?



jbrendel
27 Aug 2010, 12:29 PM
Hello!
I created a EditorGridPanel and attached a JsonStore to it. All loads fine. But when I edit cells it doesn't try to write anything back to the server.
Do I need to define and attach a JsonWriter to the store? Like what's described here (http://stackoverflow.com/questions/1202918/auto-saving-via-xmlhttprequest-from-editorgridpanel-in-extjs-3-0)?

However, the JsonStore definition that was created and exported by the Designer is confusing to me (I'm new to Ext). The definition looks like this:


MyStore = Ext.extend(Ext.data.JsonStore, {
constructor: function(cfg) {
cfg = cfg || {};
MyStore.superclass.constructor.call(this, Ext.apply({
storeId: 'MyStore',
url: 'http://localhost:8001/resource/AllCustomer/entries',
fields: [
{
name: 'ID'
...

and so on.

Where/how do I go about adding a JsonWriter to this?

Thank you very much...

Juergen

wemerson.januario
28 Aug 2010, 9:15 AM
this version of Ext Designer does not support Writer yet.
So you have to add manuallyt.
Eg:
you create a global var , just to not add everytime.

var w = new Ext.data.JsonWriter({
encode: true,
writeAllFields: false
});
And Then add the writer when you instanciate the store.


myStore= new Mystore({
writer: w
});
And you can add the store to the grid.
mygrid.store = myStore;

jbrendel
30 Aug 2010, 1:41 PM
Hello!

Thank you for your response. Yes, I had done that much already. However, the problem I had encountered (and which still persists) is that adding a writer this way changes the behavior of the JsonStore. Suddenly, it uses a POST request ("xaction=read") to retrieve data, when I really would want it to continue using GET as it did before I added the writer.

Would you happen to know how to fix the JsonStore so that it doesn't change its behavior when reading data?

I also created a separate thread for this here (http://www.sencha.com/forum/showthread.php?108481-How-can-I-keep-a-JsonStore-RESTful-even-after-adding-a-writer).

Thank you very much...

Juergen

wemerson.januario
31 Aug 2010, 7:42 PM
When you are using writing in stores. it sends 4 actions.
create, update, read and destry. To avoide it send as xactions, You can use the api like.

in Store set api config like this


api: {
read: "mydir/read.php",
create: "mydir/save.php,
update: "mydir/save.php",
destroy: "mydir/delete.php"
}