PDA

View Full Version : rowEditor/store issues create event on new record create



13 Oct 2009, 2:13 PM
I've been following the example of restful.js and there's some great stuff in there.
But lot's of hanging threads as well.

The biggest issue I notice is that most of the examples don't follow the Ext 'way' and thus do not use config objects and do not instantiate on the fly, thus they have to be converted when used in a real application that uses these prime features of Ext. This can lead to difficulty.

Also, many of the suggestions I get when I log a ticket (I'm a gold member, thus can't use the Premium forum I guess) involve the use of hard vars and onReady event but I don't think that's an option when using real time instantiation (use clicks on a tab, and sees an editable grid appear) and config objects (I don't think they allow use of the onReady event).

Correct me if my ideas above are wrong but onReady event, and hard vars are not really part of using a config object and real time instantiation because these vars don't stick around long enough to be used later, or can't be accessed from inside a config object.

So, on to my problem:

If I have a grid/store using a datawriter/proxy/reader and rowEditor, when I create a new record, the store or editor is issuing a create event and a bogus new record is POSTED and saved to the database. I am using restful.js as an example:

http://www.extjs.com/deploy/dev/examples/restful/restful.js

I use something very close to this example for most things, except I turned restful OFF. This example works well and overrides create event behavior by using the stopEditing/startEditing command of the editor to defeat the post when a new record is created. I've transposed this example to work with a config object and real time instantiation, so I don't have onReady and vars as in the example.

I seem to be able to get handles to everything I need using 'this' scope, getCmp, and getStore(). I issue the stopEditing command but the editor is still posting a create xaction when I do a new store.recordType.

Any suggestions to defeat this auto-submit event?

this.plugins[0].stopEditing();
this.getStore().add([
new (this.getStore().recordType)({name: '',date : '',ownerId: '',ownerName: '',hours: ''})
]);
this.plugins[0].startEditing(0);

I use this.plugins[0] to get a handle to the editor plugin, seems to work ok, is there a better way in my case where I can't expect a hard var in a config object to help me? This method seems to run in the debugger ok, but the event is not supressed, why?

Sorry, I'm behind a firewall and can't open a URL to see it run so for now, maybe we can talk in broad terms. How much of my assumptions sound correct, how many sound wrong? Set me straight, I can handle the truth. Do hard vars work ok in config objects? I think not. So please stop using them in your examples EXT team! Does onReady event have a place with real time instantiation? I'd guess no, so let's start avoiding using that in examples as well shall we?

thanks!

bwaters
13 Jan 2010, 9:22 AM
I was able to solve this by suspending and resuming events before and after the record is added to the store. Using your code, it would be something like this:

this.plugins[0].stopEditing();
this.getStore.suspendEvents(false);
this.getStore().add([
new (this.getStore().recordType)({name: '',date : '',ownerId: '',ownerName: '',hours: ''})
]);
this.getStore.resumeEvents();
this.plugins[0].startEditing(0);

Brian.