Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve JSON Data Array from ExtJS Store

Tags:

extjs

Is there a method allowing me to return my stored data in an ExtJS Grid Panel exactly the way I loaded it using:

var data = ["value1", "value2"]
Store.loadData(data);

I would like to have a user option to reload the Grid, but changes to the store need to be taken into account. The user can make changes and the grid is dynamically updated, but if I reload the grid, the data that was originally loaded is shown even though the database has been updated with the new changes. I would prefer not to reload the page and just let them reload the grid data itself with the newly changed store.

I guess I'm looking for something like this:

var data = Store.getData();
//data = ["value1", "value2"]

after its all said and done. Or is there a different way to refresh the grid with new data that I am not aware of. Even using the proxy still uses the "original" data, not the new store.

like image 605
sctskw Avatar asked Mar 26 '10 21:03

sctskw


4 Answers

Store.getRange() seems to be exactly what you are searching for. It will return you Ext.data.Record[] - array of records. If no arguments is passed, all the records are returned.

like image 88
Li0liQ Avatar answered Oct 21 '22 04:10

Li0liQ


A one-line approach:

var jsonData = Ext.encode(Ext.pluck(store.data.items, 'data'));

Not very pretty, but quite short.

like image 31
Automatix Avatar answered Oct 21 '22 05:10

Automatix


 function getJsonOfStore(store){
        var datar = new Array();
        var jsonDataEncode = "";
        var records = store.getRange();
        for (var i = 0; i < records.length; i++) {
            datar.push(records[i].data);
        }
        jsonDataEncode = Ext.util.JSON.encode(datar);

        return jsonDataEncode;
    }
like image 9
Jakofff Avatar answered Oct 21 '22 04:10

Jakofff


Try this:

myStore.each( function (model) {
    console.log( model.get('name') ); 
}); 
like image 4
Yasser Farghaly Avatar answered Oct 21 '22 04:10

Yasser Farghaly