View Full Version : Using grids in forms for has many data

3 Jul 2012, 10:04 AM
Looking for recommedations for best way, in ExtJS 4.1, to be able to edit a record and all related data in a single form. I am using mongoDB and the fields get return as an array of objects (Rest/Json Store). In my particular case there are many many many relationships.. so making one request per relationship is not desirable. I would assume the best way to do this is via rowEditing grids for the hasMany relationships. Now, for hasOne relationships.. mappings work great.. but hasMany.. no bueno. The goal is to do a single submit on the modified record that includes modified/added rows to the nested values. Here is a pseudo example of a record returned

first_name: 'John',
last_name: 'Doe',
aliases: [
{ first_name ="Pepe", last_name="Le Pew"},
{ first_name ="Wyatt", last_name="Erp"}

The form should look like.

First Name: [ Text Field ] Last Name: [ Text Field ]
[ Row Editor Grid]


The form only ever has one record loaded and is done via:

params: {
id: '1234'

and the load event on the store does


Anyone have an example of model, store and forms for info like this? I can't bind a grid, like I can a form field (with name property), to a dataIndex(field) of a record (Or can I?). So, I imagine I will need to load the grid data from the field values, then reapply the grid records to the model prior to submit ? Please, the above is just an example of data.. the real world data has many dozen relationships.. so this is much needed for performance. Thanks in advance.

3 Jul 2012, 10:17 AM
say you have a contact model which hasmany phoneNumbers, so contact.phoneNumbers()

you can load a form with form.loadRecord(contact)

you can do the same with a grid with grid.reconfigure(contact.phoneNumbers())

3 Jul 2012, 10:29 AM
Spot on.. I had an error in my logic.. once you pointed out reconfigure.. it was clear.. thanks!