Results 1 to 3 of 3

Thread: Model Associations/Grid Binding

  1. #1
    Sencha User
    Join Date
    Jan 2017
    Posts
    11

    Default Model Associations/Grid Binding

    I have two models, Vendor and Category, defined below:

    Code:
    Ext.define('Vendor', {
        extend: 'Ext.data.Model',
        fields: [
    	{ name: 'VendorId', type: "int" },
            { name: 'Name', type: "string" },	
    	{ name: 'CategoryId', type: "int" },
    
    
        ],
        hasOne: 'Category'
    });
    
    
    Ext.define('Category', {
        extend: 'Ext.data.Model',
        fields: [
        	{ name: 'CategoryId', type: "int" },
            { name: 'Name', type: "string" },	
        ]
    });
    I have a store in a View Model called VendorStore that uses the Vendor model. I'm binding the Store to a grid. My question is, is there a way to bind the Category Name to a grid column? Something like this:

    Code:
    dataIndex: 'Category.Name'
    I tried this, but am getting a blank in that column. I checked the store when it loads and the Category Name data is there as expected. Any help would be appreciated.

  2. #2
    Sencha User
    Join Date
    Apr 2014
    Posts
    108
    Answers
    10

    Default

    Hey,
    I think you need to set an associationKey.
    Like this:

    Code:
    hasOne:[
       {
           model: 'Category',
           associationKey: 'Category'
       }
    ]

  3. #3
    Sencha User
    Join Date
    Jan 2017
    Posts
    11

    Default

    I tried that, but still getting a blank value in the column.

Similar Threads

  1. Binding associations example
    By patrickrs in forum Ext JS 6.x Q&A
    Replies: 10
    Last Post: 23 Jun 2017, 1:43 PM
  2. Replies: 1
    Last Post: 13 Feb 2012, 12:48 AM
  3. Displaying Model Associations in a Grid?
    By william1000 in forum Ext: Discussion
    Replies: 4
    Last Post: 26 Oct 2011, 7:54 AM

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
  •