I would like to have every value of a record populated in a grid for viewing but have no idea how to do that.
For example if the JSON looks like below I want to be able to have firstName, lastName and age in the first column and the associated values in corresponding rows in the second column.
{
"people": [
开发者_StackOverflow {"firstName": "Jane",
"lastName": "Doe",
"age": 23}
]
}
Any thoughts are greatly appreciated!
Well, first you need to set columns to your grid:
columns: [
{header: 'firstName', dataIndex: 'firstName',flex:1},
{header: 'lastName', dataIndex: 'lastName', flex:1},
{header: 'age', dataIndex: 'age',flex:1}
],
then you need to define a model and a store:
Ext.define('gridModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'firstName', type:'string'},
{name: 'lastName', type:'int'},
{name: 'age', type:'string'}
]
});
var myStore = Ext.create('Ext.data.Store', {
model: 'gridModel',
proxy: {
type: 'ajax',
url : 'url of your json',
reader:{
type:'json',
root: 'people'
}
},
autoLoad:true
});
and your data should be in View. And define your store in grid: (store: myStore)
Cheers!
精彩评论