Results 1 to 2 of 2

Thread: Loading associated data into a Grid instance

  1. #1
    Sencha User
    Join Date
    Feb 2013
    Posts
    10
    Vote Rating
    1
      0  

    Default Unanswered: Loading associated data into a Grid instance

    Hey all,

    I'm trying to load some associated data into the Sencha Touch Grid. Here are my models:

    This is the main model, it has most of what I need and I call this into the grid fine right now.
    Code:
    Ext.define('rayneQa.model.WorkOrders', {
        extend : 'Ext.data.Model',
    
    
        config : {
    
    
            belongsTo:[
                   {
                       name:'assetSpecification',
                       //instanceName:'assetSpecification',
                       model:'rayneQa.model.AssetSpecification',
                       getterName: 'getAssetSpecification',
                       setterName:'setAssetSpecification',
                       associationKey:'assetSpecification'
                   }
               ],
            
            fields : [
                { name: 'id', type: 'int' },
                { name: 'orderDate', type: 'string'},
                { name: 'requiredQuantity', type: 'int'},
                { name: 'version', type: 'int'}
            ],
            
            proxy: {
                type: 'rest',
                url: 'http://localhost:8080/delmas/workorders',
                reader: {
                    type: 'json',
                    rootProperty: 'data'
                }
            }
            
        }
    });

    Here is my associated model, I want to call the 'name' field from this model with my other data.
    Code:
    Ext.define('rayneQa.model.AssetSpecifications', {
        extend : 'Ext.data.Model',
    
    
        config : {
            hasMany: {
                model: 'rayneQa.model.WorkOrders',
                name: 'orders'
            },
            
            fields : [
                'id',
                'name'
            ],
            
            proxy: {
                type: 'rest',
                url: 'http://localhost:8080/delmas/assetspecifications',
                reader: {
                    type: 'json'
                }
            }
            
        }
    });
    And Lastly, i'm using a fairly simple grid view, and need to call that name into the Board column.
    Code:
    Ext.define('rayneQa.view.OrdersGrid', {
        extend : 'Ext.ux.touch.grid.List',
        xtype  : 'grid-orders',
    
    
        config : {
            title     : 'Orders',
            store     : 'rayneQa.store.WorkOrders',
            id          : 'ordersGrid',
            
            columns  : [
                {
                    header      : 'ID',
                    dataIndex : 'id',
                    width      : '15%'
                },
                {
                    header      : 'Order Date',
                    dataIndex : 'orderDate',
                    width      : '15%'
                },
                {
                    header    : 'Quantity',
                    dataIndex : 'requiredQuantity',
                    width     : '15%'
                },
                {
                    header      : 'Version',
                    dataIndex : 'version',
                    width      : '15%'
                },
                {
                    header        : 'Board',
                    width        : '15%',
                    renderer    : function(){
                        
                    }
                }
            ],
            features : [
                {
                    ftype    : 'Ext.ux.touch.grid.feature.Sorter',
                    launchFn : 'initialize'
                },
                {
                    ftype    : 'Ext.ux.touch.grid.feature.CheckboxSelection',
                    launchFn : 'constructor'
                }
            ],
            listeners: {
                selectionchange: function() {
                    var selectedCount = Ext.getCmp('ordersGrid').getSelectionCount();
                    var btn    = Ext.getCmp('loadSelectedOrders');
                    
                    if(selectedCount == 0){
                        btn.disable();
                    } else {
                        btn.enable();
                    }
                },
                painted: function(){
                    Ext.defer(function(){ this.refresh(); }, 100, this);
                }
            }
        },
    
    
        applyStore : function() {
            return new rayneQa.store.WorkOrders();
        }
    });
    Thanks, any help would be greatly appriciated.

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,416
    Answers
    3899
    Vote Rating
    1269
      0  

    Default

    Are you returning all the associated data when you load the store or waiting to load when the associated getter method is executed?
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

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
  •