PDA

View Full Version : Save data into store persistently



ChaitaliMali
27 Sep 2013, 1:48 AM
we are getting the data from the server via REST. after that we are adding it in the store and displaying it on a grid. Till here it is working fine.
But now we want to save the data persistently in store and are unable to understand how persistent data storage works together with stores.

Here is our empty store in which we dynamically populate the data from the rest call

Code:
FileName:SalesChart1.js
Ext.define('HelloSencha.store.SalesChart1', {
extend: 'Ext.data.Store',
model: 'HelloSencha.model.SalesChart',
data: [

]
});

Code for adding data into store
var gainerStore = Ext.data.StoreManager.lookup('SalesChart1');
gainerStore .add( {'symbol': strStockSymbol, 'company' : strStockName, 'lastTrade' : strStockValue});

Though it works perfectly while displaying the data when we are connected to the network, we want to save the data persistently in the store so that we are able to access the last data in the store when we are not connected to the network.

We want to understand how to use persistant storage in EXTJS 4.2.1 using Store

existdissolve
27 Sep 2013, 10:24 AM
Check out the sync() method of Ext.data.AbstractStore: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.AbstractStore-method-sync This will synchronize the store with its configured proxy which, in your case, will trigger REST requests to the server with the new (and updated/deleted) data.

You can also configure the store with autoSync: true (http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.AbstractStore-cfg-autoSync) to avoid calling sync() manually. I prefer leaving autoSync as false, but the option is there is you'd like.