roundcrisis
roundcrisis

Reputation: 17795

How to load data into store using a MemoryProxy

I'm trying to load a JSON store using a MemoryProxy (I need to use a proxy because I use different sources depending on the scenario). It kinda looks like this:

var data = Ext.decode(gridArrayData);
var proxy = new Ext.data.MemoryProxy(data);

var store = new Ext.data.GroupingStore({               
    proxy: proxy
});
store.load();

However when I inspect this I can see that the proxy has 10 rows of data, but not the store. I'm lost as to why.

Any pointers?

Upvotes: 6

Views: 20353

Answers (3)

Felix
Felix

Reputation: 1267

This is my simple Store. All in one and ready to load your object-array right away ;-)

Ext.define('MemoryStore', {
    extend: 'Ext.data.Store',

    requires: [
        'Ext.data.proxy.Memory'
    ],

    fields: [{name: 'company'}], 

    proxy: {
        type: 'memory'
    }
});

After creating the store, your can load json via loadData

var store = Ext.create("MemoryStore");
store.loadData([
   {company:"Skynet"},
   {company:"Rocket-Solutions"},
 ]);

 console.debug(store.first().get("name"));

Upvotes: 4

Prabhu Patil
Prabhu Patil

Reputation: 16

In all the example they missed to put

autoLoad: true,

Upvotes: 0

roundcrisis
roundcrisis

Reputation: 17795

so I was missing the Arrayreader I modified the arrray example that comes with extjs replacing the arrayStore with the following

 var nameRecord = Ext.data.Record.create([                            
      {name: 'company'},
       {name: 'price', type: 'float'},
       {name: 'change', type: 'float'},
       {name: 'pctChange', type: 'float'},
       {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
]);

var arrayReader = new Ext.data.ArrayReader({}, nameRecord);          

 var memoryProxy  = new Ext.data.MemoryProxy(myData);              

 var storeDos = new Ext.data.Store({                                    
     reader : arrayReader,
     autoLoad: true,
     proxy  : memoryProxy
 });

I was thinking of putting this working copy somewhere in github, as I couldnt find anything with a memory proxy working

Upvotes: 5

Related Questions