View Full Version : What should be the jsonstore definition

9 Feb 2011, 9:47 PM

If following is the json data from server, what should be the jsonstore definition?


var store = new CQ.Ext.data.JsonStore({
root: 'list',
fields: [{name:'name', type:'string'},

9 Feb 2011, 11:25 PM
First, define a grid record class. It always useful to have it for data insertion, editing, loading into form etc

var GridRecordClass = Ext.data.Record.create([
{name: 'name'},
{name: 'age', type: Ext.data.Types.INTEGER},
{name: 'kids'}

Pass that class to DataReader config

var dataReader = new Ext.data.JsonReader({
root: 'list',
fields: GridRecordClass

Write renderer function to dislay array of kids inside grid cells

var colModel = new Ext.grid.ColumnModel([{
id: 'name',
dataIndex: 'name',
header: 'Name',
tooltip: 'Persons name',
width: 200
id: 'age',
dataIndex: 'age',
header: 'Age',
tooltip: 'Persons age (years)',
width: 50
id: 'kids',
dataIndex: 'kids',
header: 'Kids',
width: 150,
renderer: function(value, meta, record, rowIndex, colIndex, store) {
var result = [];
var total = 0;
if (Ext.isArray(value)) {
Ext.each(value, function(kid) {
result = result.join(', ');
return (total == 0) ? 'none' : String.format('Person has {0} kids, here they are: {1}', total, result);

Finally, pass that DataReader and ColModel to your GridPanel config

10 Feb 2011, 2:22 AM
Thank you. It worked.:)