Hi,
I am hoping someone on here can help me. I am using ExtJS 4.1.0 and have been looking at using nested models to populate two grids. The parent grid loads and renders fine, but while the child grid renders it does not have any data in it. I think the problem may lie with the child store not loading, but I am at a complete loss as to how to progress any further.
I have replicated my problem here:
http://www.swiftwind.co.uk/grid_test
I have also uploaded a ZIP file of my code which can simply be extracted to a webserver and run:
http://www.swiftwind.co.uk/grid_test/grids.zip
Any help would be much appreciated!
Kind Regards,
Cj
I have the following code:
data.xml
Code:
<dataset>
<row>
<id>1</id>
<fullname>Bob Holnes</fullname>
<relatives>
<relative>
<id>101</id>
<firstname>Mum</firstname>
</relative>
<relative>
<id>102</id>
<firstname>Dad</firstname>
</relative>
</relatives>
</row>
</dataset>
PeopleModel.js
Code:
Ext.define('Ext.app.models.PeopleModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'string'},
{name: 'fullname', type: 'string'}
],
proxy: {
type: 'ajax',
noCache: false,
pageParam: '',
limitParam: '',
startParam: '',
url: './app/data/data.xml',
reader: {
type: 'xml',
root: 'dataset',
record: 'row'
}
},
hasMany: {model: 'Ext.app.models.RelativeModel', name: 'relatives'}
});
RelativeModel.js
Code:
Ext.define('Ext.app.models.RelativeModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'string'},
{name: 'firstname', type: 'string'}
],
belongsTo: 'Ext.app.models.PeopleModel'
});
PeopleStore.js
Code:
Ext.define('Ext.app.stores.PeopleStore', {
extends: 'Ext.data.Store',
model: 'Ext.app.models.PeopleModel',
autoLoad: true
});
RelativeStore.js
Code:
Ext.define('Ext.app.stores.RelativeStore', {
extend: 'Ext.data.Store',
model: 'Ext.app.models.RelativeModel'
});
index.html
Code:
<html>
<head>
<title>ExtJS Grid Test</title>
<link rel="stylesheet" type="text/css" href="http://extjs.cachefly.net/ext-4.1.0-gpl/resources/css/ext-all.css"/>
<script type="text/javascript" src="http://extjs.cachefly.net/ext-4.1.0-gpl/bootstrap.js"></script>
</head>
<body>
<script type="text/javascript">
Ext.Loader.setConfig({enabled: true});
Ext.Loader.setPath('Ext.app','./app');
Ext.Loader.setPath('Ext.app.models','./app/models')
Ext.require([
'Ext.app.models.PeopleModel',
'Ext.app.stores.PeopleStore',
'Ext.app.stores.RelativeStore'
]);
Ext.onReady(function() {
Ext.create('Ext.grid.Panel', {
renderTo: Ext.getBody(),
store: Ext.create('Ext.app.stores.PeopleStore'),
columns: [{
text: 'Id',
dataIndex: 'id'
}, {
text: 'Full Name',
dataIndex: 'fullname'
}]
});
Ext.create('Ext.grid.Panel', {
renderTo: Ext.getBody(),
store: Ext.create('Ext.app.stores.RelativeStore'),
columns: [{
text: 'id',
dataIndex: 'id'
}, {
text: 'First Name',
dataIndex: 'firstname'
}]
});
});
</script>
</body>
</html>