View Full Version : Binding information from an json array to a columns

28 Jan 2011, 5:26 AM
I have an Bean

class GeneralBean {
private Integer id;
private String city;
private String client;
List<SomeBean2> promo;

class SomeBean2 {
private String type;
private Integer contactNumber;
private Integer hoursInDay;

GeneralBean bean = new GeneralBean("city", "client");
bean.addPromo(new SomeBean2("buyget", 3,4));
bean.addPromo(new SomeBean2("sampling", 4,2));

JSON for GeneralBean

"results": [
buyget: {
sampling: {

I need to show that bean in the table.

I'm doing this (the configuration for GridPanel (only major))

xtype: 'grid',
store: new Ext.data.ArrayStore({
fields: ['city', 'client', 'contactNumberBuyget', 'hoursInDayBuyget', 'contactNumberSampling', 'hoursInDaySampling']
columns: [
{header: "City", dataIndex: 'city'},
{header: "Client", dataIndex: 'client'},
{header: "Contact Number (buyget)", dataIndex: 'contactNumberBuyget'},
{header: "Hours in Day (buyget)", dataIndex: 'hoursInDayBuyget'}
{header: "Contact Number (sampling)", dataIndex: 'contactNumberSampling'},
{header: "Hours in Day (sampling)", dataIndex: 'hoursInDaySampling'}


loadData: function(results) {
Ext.each(results, function(result) {
var record = {
city: result.city,
client: result.client
Ext.each(result.promo, function(promo) {
record.contactNumberBuyget = promo.buyget.contactNumber;
record.hoursInDayBuyget = promo.buyget.hoursInDay;
record.contactNumberSampling = promo.sampling.contactNumber;
record.hoursInDaySampling = promo.sampling.hoursInDay;
}, this)
}, this)

Question whether there is an easier way to load data from a complex bean? Can I write JsonStore

store: new Ext.data.JsonStore({
fields: [
{name:'city', mapping: 'city'},
{name:'client', mapping: 'client'},
{name:'promo.buyget.contactNumber', mapping: 'contactNumberBuyget'},
may be something like this
name: {
promo: {
buyget: contactNumber
}, mapping: 'contactNumberBuyget'

{name:'promo.buyget.hoursInDay', mapping: 'hoursInDayBuyget'},
....and so on....

Then do not have to create an intermediate entry corresponding table fields. Is it possible?

31 Jan 2011, 1:44 AM
perhaps this is not possible...