Vijay
Vijay

Reputation: 363

Extjs reading complex JSON data into store

I have Json data something like this:

{

"Data":

    {
    "Columns":
    [
        {
            "Name":"Name",
            "Format":"string"
        },
        {
            "Name":"Age",
            "Format":"N2"
        }
    ],
    "Rows":
    [
        {"ExtensionData":{},"Cells":["Vikas", 23],"Emails":[{"ExtensionData": }, Email": [email protected]", "CellOrdinal":0}]},
        {"ExtensionData":{},"Cells":["Vikram", 27],"Emails":[{"ExtensionData":{},"Email":"[email protected]","CellOrdinal":0}]},     
    ]
    }
    "Grid Name":"Users"
    }
}
}

I need to bind this to my grid.

The "Columns" tag contains grid column names. "Rows" contain records of the grid. Also there are some data like Name of the grid which is fetched from the database. It's a slightly complicated structure.

How to get this data into a store? How should my model be?

Upvotes: 0

Views: 3593

Answers (1)

Vijay
Vijay

Reputation: 363

Atlast after lot of trial and error got the model ready...

Ext.define('Data', {
    extend: 'Ext.data.Model',
    fields: [
            { type: 'string', name: 'Grid Name' }
        ],
    hasMany: [{ model: 'Column', name: 'Columns' },
              { model: 'Row', name: 'Rows' }]
});

Ext.define("Column", {
    extend: 'Ext.data.Model',
    fields: [
            { type: 'string', name: 'Name' },
            { type: 'string', name: 'Format' }
        ],
    belongsTo: 'Data'
});

Ext.define("Row", {
    extend: 'Ext.data.Model',
    fields: [
            { type: 'string', name: 'Cells' },
            { type: 'string', name: 'Emails' }
        ],
    belongsTo: 'Data'
});

Upvotes: 4

Related Questions