PDA

View Full Version : How to display JsonData with sub objects in a grid



bhooshankhairnar
18 Apr 2007, 11:30 PM
My json data contains a subobject nested inside. i m not able to display the attributes of the subobject in a grid instead its being displayed as "[object Object]". Can anyone help solve this?
Also the column model is a dynamic one meaning columns are being created on fly and not hard coded as the column definition changes everytime.

Animal
18 Apr 2007, 11:37 PM
Do you mean with a field mapping like "obj.subobj[1]"?

That wasn't supported until a fairly recent release.

Post some code.

bhooshankhairnar
10 May 2007, 1:09 AM
Thanks for replying. i got the solution. What i actually meant was in the grid the output in some of the cells was "[object Object]" as my json data had sub object nested in the inner level. The solution was to override the renderer in my dynamic column definition.

Ext.grid.DynamicColumnModel = function(store){
var cols = [];
var recordType = store.recordType;
var fields = recordType.prototype.fields;
for (var i = 0; i <= fields.keys.length-1; i++)
{
var fieldName = fields.keys[i];
var field = recordType.getField(fieldName);
cols[i] = {header: field.name, dataIndex: field.name,width:300, renderer: renderObject};
}

Ext.grid.DynamicColumnModel.superclass.constructor.call(this, cols);
};

function renderObject(value, p, record)
{
if (typeof value=="object")
{
var str="";
for (property in value)
{
str = str + property.toString() + ":" + value[property] + "<br>";
}
return str;
}
else
return value;
}


Ext.extend(Ext.grid.DynamicColumnModel, Ext.grid.ColumnModel, {});