PDA

View Full Version : How to avoid hand-editing auto-generated Designer files



jbrendel
6 Sep 2010, 12:43 PM
Hello!

I have a Designer project, in which I create a JsonStore and attach it to an editable grid widget. When exporting, the Designer creates a bunch of files, many of which carry the warning: "Do NOT hand edit this file."

However, there are several places where seemingly I am required to hand-edit some of those files in order to add very basic and essential facilities. For example:


In xds_index.js, I need to add code to the onReady() function to add an 'afterEdit' handler to my grid, so that record.commit() can be called on modified records. It's an editable grid! I would have thought that this sort of logic would be included automatically? Or is there a flag I can set when I create the grid in the Designer, which then results in the 'commit' to be called automatically after a record has been edited?
In the file MyStore.js (the name here being merely what I called my JSON data store when I created it): Here the auto-generated file concludes with the line "new MyStore();". However, the store doesn't have a writer attached to it! That seems like an omission, since it is (after all) an editable grid I am attaching this store to. So, I define the writer somewhere else and now have to modify the MyStore.js file's last line to read: "new MyStore({ writer: myWriter });". Is there a way to add that writer to the store without having to edit this file? For example, can I add the writer to the store in one of the few files where I am allowed to make changes?


Thank you very much...

Juergen

jarrednicholls
6 Sep 2010, 5:37 PM
Hey Juergen,

The xds_index.js/html files are really only meant for you to view your components in the browser, but not really to use directly in your project. With that said, you can implement event handlers for your grid in the grid's implementation file (.js).

The Editor Grid will not automatically commit records (because in many cases you wouldn't want to do that...such as allowing to edit multiple columns of a record and then committing it all at once), you must call commit() on the record or commitChanges() on the store....or if you are saving the data remotely, you can call save().

The Store instantiation is a legitimate issue that we are going to take care of. We're going to add an option for instantiating the store (or not) in the generated code...that way you can opt out of automatic instantiation. For now, you can either copy/paste the code into another file, or you can add the writer after the fact:



var writer = new Ext.data.JsonWriter();
var store = Ext.StoreMgr.lookup('MyStore');
store.writer = writer;
writer.meta = store.reader.meta;


Hope that helps.