PDA

View Full Version : Stores, models, proxies and complex UI architecture



ipavlic
2 Feb 2012, 2:41 AM
Say I've got a smaller grid to select something, let's call it Parent. After selecting, related data is shown in a form (ParentInfo), and two grids (Children, Tasks).

So I define models "Parent", "ParentInfo", "Child" and "Task". I also create a model hierarchy -- one Parent has ParentInfo, and also has many Children and Tasks. So far so good. I define a proxy on the model (http://docs.sencha.com/ext-js/4-0/#!/guide/data (http://docs.sencha.com/ext-js/4-0/#%21/guide/data)), and can now call Parent.load(...). Yay! I received all of the Parent-related data.

The problem starts here. I want to actually display that data and be able to edit and store it in the database again; What is the correct approach?

A grid needs a Store to store model data in. Should I create a memory store and loadData() in it? What of the dirty and phantom rows? How are changes to the rows and newly inserted rows propagated to the original Parent instance that I loaded? What is the standard approach?

mitchellsimoens
2 Feb 2012, 9:20 AM
The grid can edit one store but if you have an association that you want to edit then you will need to use a form to edit that associated data.

ipavlic
3 Feb 2012, 12:24 AM
The grid can edit one store but if you have an association that you want to edit then you will need to use a form to edit that associated data.
That makes sense, so let's say I got a form that has some fields and grids in it. My original question still stands - how to actually bind and send data from that form.

Where is the proxy defined on? On the Parent? On a store? What does the form use?

mitchellsimoens
3 Feb 2012, 5:55 AM
Once you know which record in the grid's store you want to get the associated data, you execute the get method that is created for the association. For belongsTo association this will return a model instance in the callback and that is where you can use loadRecord on the form.

ipavlic
14 Feb 2012, 1:54 AM
Perhaps I wasn't giving enough information. Here's a quick sketch of what I want to accomplish:

31688

As I understood it, I would need to create associations like this:
Company --has-many--> Shop --has-many--> Employee

What I do not understand is how to actually display that data and implement CRUD operations. That's why I was asking where to define proxies, stores, etc. Could you be a bit more specific in your answer? Thanks a lot!

ipavlic
15 Feb 2012, 2:06 AM
I think I understand the problem.

Judging by the available information, ExtJS cannot update or delete records in nested models. So for everything other than a few simple demonstration examples, model associations are useless.