Jonathan Egerton
Jonathan Egerton

Reputation: 350

ExtJS Grid doesn't load data

I'm trying to display data in a grid by using JsonStore. The grid gets rendered, but it doesn't display the data.

The JSON data returned by API.ashx:

[{"Account":{"Username":"root","Password":null,"Enabled":true,"Id":1},"Text":"Hallo Welt!","Id":1},{"Account":{"Username":"root","Password":null,"Enabled":true,"Id":1},"Text":"hihihi","Id":3}]

My code:

Ext.onReady(function () {
var store = new Ext.data.JsonStore({
    url: 'API.ashx?type=notes&action=getAll',
    root: 'Note',
    autoload: true,
    fields: ['Text', { name: 'Id', type: 'int'}]
});

var grid = new Ext.grid.GridPanel({
    store: store,
    columns: [
        {
            id: 'Note',
            header: 'Id',
            width: 25,
            sortable: true,
            dataIndex: 'Id'
        },
        {
            header: 'Text',
            width: 160,
            sortable: true,
            dataIndex: 'Text'
        }
    ],
    stripeRows: true,
    autoExpandColumn: 'Note',
    height: 350,
    width: 600,
    title: 'Notes',
    stateful: true,
    stateId: 'grid'
});

store.load();

grid.render('grid-example');
});

Upvotes: 2

Views: 3132

Answers (1)

Jonathan Egerton
Jonathan Egerton

Reputation: 350

I just fixed it myself. I had to remove the option "root" and now it works fine.

Upvotes: 3

Related Questions