Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Associating grid selection with form via View Model

    Success! Looks like we've fixed this one. According to our records the fix was applied for EXTJS-13053 in 5.0.1.1255.
  1. #1
    Ext JS Premium Member
    Join Date
    Jul 2011
    Location
    Atlanta
    Posts
    39

    Default Associating grid selection with form via View Model

    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

    Code:
    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


    Code:
    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.

    Code:
    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.

    Code:
     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!

  2. #2
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,256

    Default

    Agreed, we need a better API for binding to a form. Will open a ticket for it.
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  3. #3
    Ext JS Premium Member
    Join Date
    Jul 2011
    Location
    Atlanta
    Posts
    39

    Default

    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).

  4. #4
    Sencha Premium Member
    Join Date
    Apr 2012
    Posts
    44

    Default

    +1

  5. #5

    Default

    +1

  6. #6
    Sencha Premium Member
    Join Date
    Jun 2008
    Posts
    381

    Default

    +1
    I`m from Holland!

  7. #7
    Sencha Premium Member
    Join Date
    Jun 2008
    Posts
    381

    Default

    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?
    I`m from Holland!

  8. #8
    Sencha User
    Join Date
    Jun 2008
    Posts
    12

    Default

    +1

  9. #9
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,256

    Default

    This is already possible in 5.0.1:

    https://fiddle.sencha.com/#fiddle/8uk
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  10. #10
    Sencha Premium Member
    Join Date
    Sep 2013
    Posts
    9

    Default now how bind dirty

    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.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •