Results 1 to 6 of 6

Thread: Grid column field value from model association

  1. #1

    Default Grid column field value from model association

    Hi!

    From the following, how can i get an association field value from parent_id?

    Here is the grid columns:
    Code:
    this.columns = [
                {header: 'Name',  dataIndex: 'name',  flex: 1},
                {header: 'Parent',  dataIndex: 'parent_id',  flex: 1}
            ];
    The model used in the grid row:
    Code:
    Ext.define('AM.model.AccountGroup', {
        extend: 'Ext.data.Model',
        fields: [
            {name: 'id', type: 'int'},
            {name: 'name', type: 'string'},
            {name: 'active', type: 'int'},
            {name: 'parent_id', type: 'int'}
        ],
        belongsTo: 'AccountGroup'
    });

    I want to show in the grid, instead of the parent_id, the parent AccountGroup name.

    Thanks!

  2. #2
    Sencha User
    Join Date
    Mar 2010
    Posts
    9

    Default

    Did you have a solution for this issue already?

  3. #3

    Default

    Hi! Thank you for replying!

    No. I could not find a solution using the Grid, so now I'm using a TreePanel...

    But I still need the solution for the GridPanel.

    Thanks.

  4. #4
    Sencha User
    Join Date
    Jun 2008
    Posts
    157

    Default

    I was having the same problem, I think it's something the framework should support by itself, but you can achieve it by using a renderer.

    Code:
    {
      header: 'Parent', 
      dataIndex: 'parent_id',  
      flex: 1, 
      renderer: function(value, meta, record, rowIndex, colIndex, store, view) {
        return record.getAccountGroup().get("name");
      }
    }
    Keep in mind, that if the associated object is not loaded, this will not work, since the loading is asynchronous (via the proxy) and the renderer is synchronous. I guess you could make it work asynchronously too, via some hacking or calling to some gridView method.

  5. #5
    Sencha User
    Join Date
    Feb 2012
    Posts
    21

    Default

    Quote Originally Posted by wiznia View Post
    Keep in mind, that if the associated object is not loaded, this will not work, since the loading is asynchronous (via the proxy) and the renderer is synchronous.
    How to deal with that problem? I really need solution for this :/ My grid have now empty cells at launch and I must refresh that grid to see data inside.

  6. #6
    Sencha User
    Join Date
    Jun 2008
    Posts
    157

    Default

    You need to send the associated object, to the grid store. There are some examples on how to do that in the docs. If you send the associated object inn the same response, then the call is synchronous, and it works as expected.

Tags for this Thread

Posting Permissions

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