views:

675

answers:

1

I am trying to populate a grid using a DirectStore. No data appears in the grid although I can see data in Firebug. I even tried to dump the data in a DataView to see if i am maybe messing up in the GridPanel but nothing got displayed there either. Tried using both JSON and XML readers to no avail.

Any idea what might be going on here?

Here is the javascript:

var RecordDef = Ext.data.Record.create([
    {name: 'ProgramName'}
]);

var jsonReader = new Ext.data.JsonReader({
    root: 'list',
    fields: [
           {name: 'ProgramName',  type: 'string'}
        ]
});

var xmlReader = new Ext.data.XmlReader({
    record: "ProgramName"
}, RecordDef);

var mystore = new Ext.data.DirectStore({
    autoLoad: true, 
    reader: jsonReader,
    paramsAsHash: false,
    storeId:'mystore',
    directFn: DataAction.getProgramNames
});

var grid = new Ext.grid.GridPanel({
    renderTo:'grid',
    store: mystore,
    columns: [
        {id:'ProgramName', header: 'ProgramName', sortable: true, dataIndex: 'ProgramName'}
    ],
    stripeRows: true,
    autoExpandColumn: 'ProgramName',
    fitToFrame: true,
    fitContainer: true,
    height: 200,
    title: 'Coolness',
});

And this is the data I'm getting back as seen in Firebug:

{"result":
     "{\"list\":
           [{\"ProgramName\":\"Name1\"},
            {\"ProgramName\":\"Name2\"},
            {\"ProgramName\":\"Name3\"},
            {\"ProgramName\":\"Name4\"}]}",
 "tid":2,"action":"DataAction","method":"getProgramNames","type":"rpc"}
+1  A: 

Your result value is a string, not an object named list that contains an array. It should look like this (note that the double-quotes around the entire "result" value have been removed):

{"result":
     {\"list\":
           [{\"ProgramName\":\"Name1\"},
            {\"ProgramName\":\"Name2\"},
            {\"ProgramName\":\"Name3\"},
            {\"ProgramName\":\"Name4\"}]},
 "tid":2,"action":"DataAction","method":"getProgramNames","type":"rpc"}

With that, you should not need to escape all of your double-quotes either.

bmoeskau
D'oh! We were switching from getting XML and JSON and one of the classes was using JsonHierarchicalStreamDriver() to return a JSON _String_ instead of having the direct method return a list of objects.Thanks!
edlftt
Did this solve the problem? If so, it would be great if you'd accept my answer.
bmoeskau
Sorry .. it did indeed :)Thank you so much for your reply.
edlftt