2
votes

I hope someone helps me out.

I want to load my grid with xml file's data, locally. I created model,store and grid. I load the store in render event of grid.

The problem is, Store is loaded but the grid is still empty. I looked at the grid at console, and grids items contains the loaded data, but grid doesnt contain the data on the screen.

Here is the model

Ext.define('BTOM.model.test.test', {
    extend: 'Ext.data.Model',
    fields: [
        { name: 'id', type: 'string' },
        { name: 'name', type: 'string' },
        { name: 'phone', type: 'string' }
    ]
});

Here is the store

Ext.define('BTOM.store.test.test', {
    extend: 'Ext.data.Store',
    model: 'BTOM.model.test.test',
    autoLoad: false,

    proxy: {
        type: 'memory',
        reader: {
            type: 'xml',
            root: 'users',
            record: 'user'
        }
    }
});

And the grid

Ext.define('BTOM.view.test.test', {
    extend: 'Ext.grid.Panel',
    store: 'BTOM.store.test.test',
    alias: 'widget.test',
    title: 'Test',

    initComponent: function () {

        this.columns =
        [
            { header: "Id", width: 120, dataIndex: 'id', sortable: false },
            { header: "Name", width: 180, dataIndex: 'name', sortable: false },
            { header: "Phone", width: 115, dataIndex: 'phone', sortable: false}
        ];

        this.callParent(arguments);
    },
});

And where I load the store is

render: function (grid, eOpts) {
    var store = grid.getStore();
    var data =
        '<?xml version="1.0" encoding="utf-8"?>' +
           '<users> ' +
              '<user><id>1</id><name>Bll QASD</name><phone>333 2211</phone></user> ' +
              '<user><id>2</id><name>Asd QWF</name><phone>444 2211</phone></user> ' +
              '<user><id>3</id><name>Zas QWE</name><phone>555 2211</phone></user> ' +
           '</users>';
        var dataXml = (new DOMParser()).parseFromString(data, 'text/xml');
    console.log(dataXml);
    store.loadRawData(dataXml, true);
    console.log(grid);

}

dataXML document is created without problem. grid seems to contain the data (by firebug, I can see) but datagrid is empty, doesnt show the data!

1

1 Answers

0
votes

Ok, the error is that you are defining the store but not creating it. So the grid just has the name of the store but it expects a store instance, or is that some thing you have missed in the code snippet above. I used the same code and here is a running example: https://fiddle.sencha.com/#fiddle/oel