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"}}
]
}