PDA

View Full Version : Can't load json data in a grid



softwareplay
17 Sep 2013, 12:40 AM
Hello!
I'm building a grid in a new window, all in handled with an ajax call which passes the json data to the store of the grid. I'm pasting the entire code of the new window, so you will know if i'm missing something or there is something wrong in the entire solution.


Ext.create('Ext.window.Window', {
title: 'Admants',
height: 200,
width: 400,
layout: 'fit',
items: {
xtype: 'grid',
border: false,
columns: [
{
text : 'id',
flex : 1,
sortable : true,
dataIndex: 'id'
},
{
text : 'name',
width : 300,
sortable : true,
dataIndex: 'name'
}],
store: Ext.create('Ext.data.Store', {
autoLoad: true,
storeId: 'Storename',
fields: ['id','name'],
data : jsonObject,
model: 'ModelName',
proxy: {
type: 'memory',
reader: {
type: 'json',
record: 'jsonRoot'
}
}
})
}}).show();

softwareplay
17 Sep 2013, 5:35 AM
Ive writte jsonstore instead of the simple store, but it doesn't work neither. This is the code:


store: Ext.create('Ext.data.JsonStore', {
autoLoad: true,
storeId: 'StoreName',
fields: ['id','name'],
data : JsonObject,
model: 'ModelName',
proxy: {
type: 'memory',
reader: {
type: 'json',
record: 'jsonRoot'
}
}
})

softwareplay
17 Sep 2013, 6:45 AM
The following is the right code for the task:


Ext.define('Admants', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'int', convert: null, defaultValue:undefined},
{name: 'name', type: 'string', convert:null, defaultValue:undefined}
],
idProperty: 'id'
});
var Admantstore = Ext.create('Ext.data.Store', {
autoLoad: true,
storeId: 'Admants',
fields: ['id','name'],
data : obj,
model: 'Admants',
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'admants'
}
}
})
Ext.create('Ext.window.Window', {
title: 'Admants',
height: 200,
width: 400,
layout: 'fit',
items: {
xtype: 'grid',
border: false,
store: Admantstore,
columns: [
{
text : 'id',
flex : 1,
sortable : true,
dataIndex: 'id'
},
{
text : 'name',
width : 300,
sortable : true,
dataIndex: 'name'
}],
}}).show();