Search code examples
extjsmodel-view-controllerextjs4ext-direct

Extjs 4 grid store MVC with Ext direct url is undefined


I have a grid with store, and I want to load on render or click a button, but when I try to load the grid, got an url is undefined error. I need to use Ext direct, so no url. What should I do?

Ext.define('My.view.Grid' ,{
    extend: 'Ext.grid.Panel',
    //...
    store: 'MyStore',
    //...
}

Store:

Ext.define('My.store.MyStore', {
    extend: 'Ext.data.JsonStore',

    //...

    model: 'My.model.MyModel',

    proxy: {
        type: 'direct',
        directFn: Ext.direct.Class.function,
        paramOrder: ['start', 'limit', 'sort', 'active'],
            reader: {
                type: 'json',
                root: "data",
                idProperty: 'id',
                totalProperty: "all"
            },
            extraParams: {
                active: 1
            }
    },
    remoteSort: true,
    sorters: ['name']

    //...

Solution

  • Extend your store from Ext.data.Store:

    Ext.define('My.store.MyStore', {
        extend: 'Ext.data.Store',
        // ...
    });
    

    If you see the source code of Ext.data.JsonStore, you will see that there is predefined an ajax proxy:

    constructor: function(config) {
        config = Ext.apply({
            proxy: {
                type  : 'ajax',
                reader: 'json',
                writer: 'json'
            }
        }, config);
        this.callParent([config]);
    }