1. #1
    Sencha User
    Join Date
    Dec 2009
    Location
    Brasil
    Posts
    6
    Vote Rating
    0
    Everton Luiz Pascke is on a distinguished road

      0  

    Default Associations and Grid

    Associations and Grid


    Hi people,
    I'm trying to use Associations with Grid.
    Is it possible?
    I'm doing with belongsTo, but unsuccessfully.
    Below codes:

    Models

    Code:
    Ext.define('App.model.Action', {
    	extend: 'Ext.data.Model',
    	idProperty: 'id',
    	fields: [
    		{ name: 'id', type: 'int' },
           	{ name: 'descricao', type: 'string' }
    	]
    });
    
    Ext.define('App.model.Metodo', {
    	extend: 'Ext.data.Model',
    	idProperty: 'id',
    	fields: [
    		{ name: 'id', type: 'int' },
           	{ name: 'descricao', type: 'string' }
    	]
    });
    
    Ext.define('App.model.Funcionalidade', {
    	extend: 'Ext.data.Model',
    	idProperty: 'id',
    	fields: [
    		{ name: 'id', type: 'int' },
           	{ name: 'modo', type: 'string' }
    	],
    	associations: [
            { type: 'belongsTo', model: 'App.model.Action', name: 'action'},
            { type: 'belongsTo', model: 'App.model.Metodo', name: 'metodo'}
        ]
    });
    Store

    Code:
    Ext.define('App.store.Funcionalidade', {
    	extend: 'Ext.data.Store',
    	autoLoad: true,
    	remoteSort: true,
    	model: 'App.model.Funcionalidade',
    	proxy: {
    		type: 'ajax',
    		url: 'funcionalidade.carregar',
    		reader: {
    			type: 'json',
    			root: 'data',
    			idProperty: 'id',
    			totalProperty: 'total',
    			successProperty: 'success'
    		}
    	},
    	sorters: [
    		{ property: 'modo', direction: 'ASC' }
    	]
    });
    Grid Columns

    Code:
    columns = [
        { 
        	header: 'Action',  
        	dataIndex: 'action.descricao',  
        	flex: 1
        },
        { 
        	header: 'Método',  
        	dataIndex: 'metodo.descricao',  
        	flex: 1 
        },
        { 
        	header: 'Modo',  
        	dataIndex: 'modo',  
        	flex: 1
        }
    ];
    Data

    Code:
    {
    	"total":2,
    	"success":true,
    	"data":[
    		{"id":"40:1","modo":"LO","metodo":{"id":1,"descricao":"Consultar"},"action":{"id":40,"descricao":"Banco"}},
    		{"id":"40:3","modo":"LO","metodo":{"id":3,"descricao":"Editar"},"action":{"id":40,"descricao":"Banco"}}
    	]
    }
    Everton Luiz Pascke
    Certifications: SCJP/SCWCD

  2. #2
    Sencha User
    Join Date
    Dec 2009
    Posts
    6
    Vote Rating
    0
    Yuriksan is on a distinguished road

      0  

    Default Also interested

    Also interested


    Hi, I'm also trying to figure out a solution to this today, any progress on your side?

  3. #3
    Sencha User
    Join Date
    Dec 2009
    Location
    Brasil
    Posts
    6
    Vote Rating
    0
    Everton Luiz Pascke is on a distinguished road

      0  

    Default


    No progress Yuriksan.
    When I need access with dot notation, I use implicit model.
    I create my data store without model and configure the fields with names using the access operator.

    See http://www.sencha.com/forum/showthre...ation-in-field
    Everton Luiz Pascke
    Certifications: SCJP/SCWCD

  4. #4
    Sencha Premium Member mik3e's Avatar
    Join Date
    Jan 2012
    Location
    Vienna / Austria
    Posts
    81
    Vote Rating
    1
    mik3e is on a distinguished road

      -1  

    Default


    Just another note:
    After two days of sandboxing I found out that associations only really work if the proxy is defined in the model, not in the store (ExtJS 4.1.3).

    It seems like the model is not passing the proxies URL to the "magic" getter method when the proxy is defined in the store. This results in an index out of bounds exception in the buildURL method.

Thread Participants: 2