Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load data into store using a MemoryProxy

Tags:

extjs

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?

like image 394
roundcrisis Avatar asked May 17 '10 19:05

roundcrisis


2 Answers

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

like image 92
roundcrisis Avatar answered Sep 23 '22 16:09

roundcrisis


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"));
like image 37
Felix Avatar answered Sep 24 '22 16:09

Felix