PDA

View Full Version : Writer in JsonStore



erdna
24 May 2010, 11:21 PM
How I can integrate a Writer into a JsonStore if I create the Store with the ExtDesigner?

jarrednicholls
25 May 2010, 5:40 AM
Writers are not currently supported, but look for them in a near future release. You can, in the meantime, sub-class your exported Store in a separate file that is not overwritten upon export, and define a writer there. Thanks.

dnorman
3 Apr 2011, 8:01 PM
exactly how near? lol
*Checks watch*

I'm having this issue now, a year later.
Suggestions?

hschaefer123
4 Apr 2011, 3:13 AM
I'm using a prototyped store methods to apply api settings to store and add a writer.
I also added the api inside my logic class beside from ui class, because in former releases it was not possible to add API methods without loading valid API declarations (Thanks to Jarred for implementing also JavaScript API use).

Include the following code after ext lib and use it as described inside comment.

/**
* Workaround for ExtDesigner Direct Stores
* currently it is not possible to set an apiConfigs with CamelCase operations
* currently it is not possible to configure a writer
* @param {Object} apiConfig the api config that should be used by the store
*
* 1) configure your grid with an API like this
*
* MyGrid = Ext.extend(MyGridUi, {
* api: {
* create : ArticleBean.writeRecord,
* read : ArticleBean.find,
* update : ArticleBean.writeRecord,
* destroy : ArticleBean.deleteRecord
* }
*
* 2) call the fix function inside initialisation
*
* initComponent: function() {
* MyGrid.superclass.initComponent.call(this);
* if (this.api) this.store.setApi(this.api); // must be after super call
* ...
*/
Ext.override(Ext.data.Store, {
setApi : function(apiConfig) {
// fix for ExtDesigner bug setting API with CamelCase function names

// add proxy
if (!this.proxy) this.proxy = new Ext.data.DirectProxy();

// add event listener for CRUD operations (normally applied automatically if using a writer config)
if (Ext.isDefined(apiConfig.create)) {
this.proxy.setApi(Ext.data.Api.actions.create, apiConfig.create);
this.on('add', this.createRecords, this);
}
if (Ext.isDefined(apiConfig.read)) {
this.proxy.setApi(Ext.data.Api.actions.read, apiConfig.read);
this.on('clear', this.onClear, this);
}
if (Ext.isDefined(apiConfig.update)) {
this.proxy.setApi(Ext.data.Api.actions.update, apiConfig.update);
this.on('update', this.updateRecord, this);
}
if (Ext.isDefined(apiConfig.destroy)) {
this.proxy.setApi(Ext.data.Api.actions.destroy, apiConfig.destroy);
this.on('remove', this.destroyRecord, this);
}

// add writer (adding writer to store is currently not supported by ExtDesigner)
this.writer = new Ext.data.JsonWriter({
encode: false,
writeAllFields: true,
meta: this.reader.meta
});
}
});

mboreback
29 Aug 2011, 8:07 PM
I have done it like this in extdesigner 1.1
In my grid.js file I added this pease of code
I have not verified if this works with extdesigner 1.2, but someone else might know

var store = Ext.StoreMgr.lookup('ClientStore');
store.writer = new Ext.data.JsonWriter({meta: store.reader.meta,writeAllFields: true,listful: true,encode: false});
store.on({
scope: store,
add: store.createRecords,
remove: store.destroyRecord,
update: store.updateRecord,
clear: store.onClear
});

Will.Denissen
5 Sep 2011, 11:52 PM
Can you give an example?

Will.Denissen
5 Sep 2011, 11:53 PM
Writers are not currently supported, but look for them in a near future release. You can, in the meantime, sub-class your exported Store in a separate file that is not overwritten upon export, and define a writer there. Thanks.


Can you give an example of the above?