Results 1 to 9 of 9

Thread: grid column - bind model association

  1. #1
    Sencha User razvanioan's Avatar
    Join Date
    Feb 2008
    Location
    Romania
    Posts
    135
    Answers
    4

    Default grid column - bind model association

    This is gettin' me crazy.....haven't figured it out (yet) how to use correct data binding.

    What am I trying to achieve here, is to display in a grid's column some property from another store for which I have the ID (using model association).

    Short scenario (fiddle bellow):

    - model Department (id, name)
    - store Departments (auto loaded on application initialisation)
    - model Employee (id, firstName, lastName, departmentId - reference Department)
    - grid with Employees, display Department.name (using model association / reference & data binding)

    I have done it using renderer function over departmentId column (where I'm fetching department name from departments store), but I thought it should be a bind / tpl method (but I cannot make it work)

    Is this possible or not, and if yes, how ?
    What is the best solution to render such data ?

    Others (and me before) were delivering the full departmnent name together with it's id on employees records (denormalisation) and getting the full departments data only when needed (combo / filter list) but I thought that by loading such kind of stores at the beggining, I can make use of data binding more easily...



    Thank you !
    ---
    Razvan Ioan ANASTASESCU
    Senior WEB Developer

  2. #2
    Sencha User
    Join Date
    Jan 2010
    Posts
    4

    Default

    I have a similar question on this thread. Are you using sessions?

  3. #3
    Sencha User razvanioan's Avatar
    Join Date
    Feb 2008
    Location
    Romania
    Posts
    135
    Answers
    4

    Default

    I know, I've also seen your post one hour after I've created my post (although I was first searching the forum).

    Yes, if you look at my fiddle, there's a base model which builds up the schema, and also there's a session started on the main component....

    As well, there's a last line which is writing to console log the session object....
    ---
    Razvan Ioan ANASTASESCU
    Senior WEB Developer

  4. #4
    Sencha User razvanioan's Avatar
    Join Date
    Feb 2008
    Location
    Romania
    Posts
    135
    Answers
    4

    Default

    nothing on this one ?

    I will stick with custom renderer config option until then...
    ---
    Razvan Ioan ANASTASESCU
    Senior WEB Developer

  5. #5
    Sencha User
    Join Date
    Mar 2010
    Posts
    20

    Default

    Have you ever found a solution to your problem?
    Just like you I find it hard to believe that you have to use custom column renderers for something that should be possible by using associations ...

  6. #6
    Sencha User razvanioan's Avatar
    Join Date
    Feb 2008
    Location
    Romania
    Posts
    135
    Answers
    4

    Default

    nope

    just used renderer function like I've stated for the moment, to get the name from the store based on the ID in grid's data.

    I had multiple issues in understanding / using data bind, and I think it will take some time until it will be good to go with.

    For example, on grid selected record, if you deselectAll() rows, the last selected one will still be there (the bind doesn't respond to that). For this, somebody found a way with a bind formula to send back an empty record/id if no selected record in the grid, but haven't tested that one yet, used old selectionChange event to the manual filter on the child grid store.

    Yesterday I have also succesfully found a solution to bind a form to a grid where I had a reference column (province / state) which has a non integer id field (but a string code). It was getting only first letter from the code in the combobox, and it was getting me crazy.

    I figured it out that I need to config the role of the reference correctly in order to work...
    ---
    Razvan Ioan ANASTASESCU
    Senior WEB Developer

  7. #7
    Sencha Premium Member
    Join Date
    Sep 2014
    Location
    Mexico
    Posts
    24
    Answers
    3

    Default

    There is simply not enough documentation regarding full usage of data-binding, associations and sessions. Many of the stuff I've accomplished has been through try-and-error. I'm starting to think Sencha would only share such information with paid customers.

  8. #8
    Sencha User
    Join Date
    Feb 2012
    Posts
    27
    Answers
    3

    Default

    Has somebody a solution for this ? Why does this not work ?

  9. #9
    Sencha User
    Join Date
    Jun 2012
    Location
    Pretoria - South Africa
    Posts
    22
    Answers
    4

    Default

    If I can share some thoughts on this:
    • Nothing wrong with using a renderer function - binding anything to the column will not resolve down per underlying store record.
    • Model associations are quite sensitive to the schema and session they're attached to. In your fiddle, the session is totally unaware of the Department records (because as you state, the store is loaded elsewhere).
    Couple of ways you could use associations and include Department recs in the session, but here's one way to change your fiddle:
    PHP Code:
    // add 'session: true' to the employees store in the viewModel
    employees: {
        
    model'Employee',
        
    sessiontrue,
        
    data: ...
    }

    // change the column renderer to use the associated data
    renderer: function(val,meta,rec) {
        return 
    rec.getDepartment().get('name');
    }

    // Just Before the last console.log(...
    // Add the (pre-loaded) Department records to the session
    deptStore.each(function(rec){
        
    container.getSession().adopt(rec); 
    }); 

Posting Permissions

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