0
votes

Can u help me with rest store, please. I want my store become REST, I saw some samples where HttpProxy was used and tried to do the same, but it dosn't work.

As i noticed in samples store was always created like: var store = Ext.create... If problem in this, then i don't know where to invoke Ext.create, and previously I always used storeId in grid and it worked well.

P.S. why grid couldn't be created without store data just with blank fields?

Here is my 'TestStore' code:

Ext.define('MVC.store.Notes', {
extend  : 'Ext.data.Store',

requires : [
    'MVC.model.Note'
],

storeId : 'TestStore',
model   : 'MVC.model.Note',
autoLoad: true,
proxy: {
    type: 'rest',
    url: 'rest/notes',
    reader: {
        type: 'json',
        rootProperty: 'data'
    },
    writer: {
        type: 'json'
    }
}
});

And Grid:

Ext.define('MVC.view.NotesGrid', {
extend: 'Ext.grid.Panel',
xtype: 'notesGrid',

title: 'Note-list',

//  store: 'Notes',
store: 'TestStore',
columns: [
    {
        text: 'Name',
        dataIndex: 'name',
        flex: 1
    },
    {
        text: 'Creation Date',
        xtype: 'datecolumn',
        format: 'd-m-Y',
        dataIndex: 'createDate',
        flex: 1
    },{
        text: 'Last Modified',
        xtype: 'datecolumn',
        format: 'd-m-Y',
        dataIndex: 'modifiedDate',
        flex:1
    }, {
        text: 'Text',
        dataIndex: 'noteText',
        flex: 3
    }
]
});
1
From your code snippets, I don't see why it shouldn't work. I guess more details are required (e.g. what exactly isn't working, which error messages you get in browser console and how you create an instance of that store). - Alexander

1 Answers

1
votes

Not answering the main question, only your side question:

  • When you Ext.define() a store, you define the class.
  • When you Ext.create() a store, you define the instance.

The class won't be able to hold any data, only an instance can.

If you add your store's class name to the stores array in your application definition in the main Application.js file, you tell your application to create one global store instance of that class.

From a store class with a fixed store Id, you can only create one instance per application; from a store class without a fixed storeId, you can create multiple instances (e.g. one per grid).