Hi,
Problem: Access 'one to one' relationship model attributes in Grid.
Dot notation is not working in Grid panel.
Data:
Code:
{
"data": [
{
"name": "tom",
"type": {
"animal": "cat",
"primaryFood": "milk"
}
},
{
"name": "jerry",
"type": {
"animal": "mouse",
"primaryFood": "cheese"
}
}
]
}
Model:
Code:
Ext.define('Pet', {
extend: 'Ext.data.Model',
requires: [
'Ext.data.field.Field'
],
fields: ["name"],
hasOne: [{
name: 'type',
model: "PetType",
associationKey: 'type'
}]
});
Ext.define('PetType', {
extend: 'Ext.data.Model',
requires: [
'Ext.data.field.Field'
],
fields: ["animal", "primaryFood"]
});
Store:
Code:
Ext.define('PetStore', {
extend: 'Ext.data.Store',
requires: [
'Pet',
'Ext.data.proxy.Ajax',
'Ext.data.reader.Json'
],
constructor: function (cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
storeId: 'PetStore',
autoLoad: true,
model: 'Pet',
proxy: {
type: 'ajax',
url: 'data/Pets.json',
reader: {
type: 'json',
rootProperty: 'data'
}
}
}, cfg)]);
}
});
Grid Panel:
Code:
Ext.define('PetView', {
extend: 'Ext.panel.Panel',
items: [{
xtype: 'grid',
title: 'Pets',
store: "PetStore",
columns: [{
text: 'Pet Name',
dataIndex: 'name',
xtype: 'gridcolumn'
},
{
text: 'Pet Type',
dataIndex: 'type.animal',
xtype: 'gridcolumn'
},
{
text: 'Primary Food',
dataIndex: 'type.primaryFood',
xtype: 'gridcolumn'
}],
plugins: [
{ptype: 'rowediting', pluginId: 'rowediting'}
]
}]
});
I expect the result to be:
Code:
Pet Name | Pet Type | Primary Food
tom | cat | milk
jerry | mouse | cheese
Data index is not working in the grid panel:
HTML Code:
dataIndex: 'type.animal'
Any help is appreciated!
I want my model to have the one to one relationship.
I do not want my Pet model to have the PetType's attributes.
Ie., I don't want {name: "type.animal", mapping: "type.animal"} in Pet Model.