PDA

View Full Version : [FIXED] Associating grid selection with form via View Model



Carun
8 Apr 2014, 6:49 PM
Question in short - How to associate the current selection as the record for a form?

Example:
Within a container, there is a grid (center) and a form panel (south). A view model is associated with the parent (container), and the data for the grid comes from it.

View


Ext.create('Ext.container.Container', {

viewModel : {
type: 'empmodel'
},

controller: 'empcontroller',

session: true,

items: [
{
xtype: 'employeegrid',
title: 'Employees',
bind: '{employees}',
region: 'center',
reference: 'empGrid'
}, {
xtype: 'empdetail',
region: 'south',
height: 300
}
]
});


ViewModel



alias: 'viewmodel.empmodel',


stores: {
employees: {
model: 'Employee',
autoLoad: true
}
}


I don't see a bind for the form, so the only way I could get this to work was by associating the selected record to the form through a formula on the view model.



formulas: {
emp: {
bind: {
record: '{empGrid.selection}'
},
get: function (data) {
return data.record;
}
}
}


Form fields bind to {emp.fieldname} and this works. Updates on the form immediately reflect on the grid. So far so good.

I tried the links config on the view model like this, but that didn't work. It doesn't like anything, but an actual id.



links: {
emp: {
reference: 'Employee',
id : {solutionGrid.selection.id}
}
}


Maybe there is an easier way to do this and I haven't figured that one yet. So any pointers on how to easily associate the current selected record to a form (just via config) w/o having to write a formula or listeners will be of great help.

Thanks!

evant
8 Apr 2014, 7:45 PM
Agreed, we need a better API for binding to a form. Will open a ticket for it.

Carun
9 Apr 2014, 5:16 AM
Thanks!

This is a pretty common requirement of ours. 80% of the transactions (100's) in our SPA work with a grid (or some form of listing, chart) and an associated Form to display or edit the selection along with it's associated data. Having an easier way to bind selection/record to a Form will be greatly appreciated.

I hope this change makes it to the release (if not in to another beta).

sriram139
30 Apr 2014, 11:09 AM
+1

jorgemanrubia
2 Jun 2014, 10:20 PM
+1

Scorpie
21 Jul 2014, 5:33 AM
+1

Scorpie
21 Jul 2014, 7:09 AM
I`m having trouble using the OP's example of binding to formulas in a grid with a seperate window. Anybody got it working with seperate detail window?

mahe8116
14 Aug 2014, 5:16 PM
+1

evant
14 Aug 2014, 5:54 PM
This is already possible in 5.0.1:

https://fiddle.sencha.com/#fiddle/8uk

svidal
9 Oct 2014, 9:27 PM
In this scenario, grid-form, which detects event when the form is dirty, and as I bind to a button.


I have tried and does not work with formulas.

pscanlon1
26 Dec 2014, 8:54 AM
This is already possible in 5.0.1:

https://fiddle.sencha.com/#fiddle/8uk


How do you bind to links ? for Example.



links:{
someData:{
type:'SomeType',
id:'{aBind}'
}
}

This doesnt work, in a more common scenario, you open a modal window and pass an ID, and you want to load a single record with that passed var, right now, I have to do (in the viewController init method..)


this.setLinks({
someData:{
type:'SomeType',
id:ID
}
});

SpecialAgent
20 Apr 2017, 11:56 PM
This is already possible in 5.0.1:

https://fiddle.sencha.com/#fiddle/8uk

And already broken in >= 5.1

:-?

sorry for grave rape