Search code examples
extjsgridpanel

Ext.grid.Panel loading from other domain


When I load from memory everything works fine

Ext.define('MyApp.store.Personnel', {
    extend: 'Ext.data.Store',

    alias: 'store.personnel',

    model: 'MyApp.model.Personnel',

    data: { items: [
        { name: 'Jean Luc', email: "jeanluc.picard@enterprise.com", phone: "555-111-1111" },
        { name: 'Worf',     email: "worf.moghsson@enterprise.com",  phone: "555-222-2222" },
        { name: 'Deanna',   email: "deanna.troi@enterprise.com",    phone: "555-333-3333" },
        { name: 'Data',     email: "mr.data@enterprise.com",        phone: "555-444-4444" }
    ]},

    proxy: {
        type: 'memory',
        reader: {
            type: 'json',
            rootProperty: 'items'
        }
    }
});

Then I try to load from api in other domain, changing the proxy:

proxy: {
    type: 'jsonp',
    url: 'http://localhost:62770/api/user'
},

But it doesn't work. The request is not even sent

The request from the controller works fine

Ext.define('MyApp.view.main.MainController', {
    extend: 'Ext.app.ViewController',

    alias: 'controller.main',

    onItemSelected: function (sender, record) {
        GetUsers()
    },
});

async function GetUsers() {
    const response=await fetch('http://localhost:62770/api/user',{mode: 'no-cors'});
    .................
}

Solution

  • You have to add autoLoad the store or load it manually.

    // ==> in proxy
    autoLoad: true
    // ==> in controller
    myStore.load();