-
23 Dec 2010 6:34 PM #1
Data Store Delete All/ Remove All Items
Data Store Delete All/ Remove All Items
Hi all,
I have set up a data store with a data model set to localStoreage and I would like to delete all items/records. My application is running locally under file://
Here is my code:
Ext.regModel("Message", {
fields: [
{ name: "MessageId", type: "int" },
{ name: "Msg", type: "string" }
],
proxy: {
type: 'localstorage',
id: 'stored-inbox'
}
});
Ext.regStore('Messages', {
model: 'Message',
storeId: 'messagesStore',
autoLoad: true
});
//delete methods tried
Ext.StoreMgr.clear('Messages');
Ext.StoreMgr.clear('messagesStore');
store.destroy();
store.removeAll();
store.sync(); //called after destroy/removeAll methods
The only way of deleting the localStorage items I can find that works is by calling localStorage.clear();
Has anyone got any ideas? Is it perhaps not working because I'm working from a local file:// and not a domain?
thanks
Francesco
-
27 Dec 2010 1:50 PM #2
Same here
Same here
For me this worked:
deviceStore.getProxy().clear();
Where deviceStore was a
And the device model was connected to a localstorageproxyCode:deviceStore = new Ext.data.Store({ model: 'Device', //autoLoad : true, });
Code:var Device = Ext.regModel('Device', { fields: [ {name: 'pairing_key', type: 'string'}, {name: 'pairing_token', type: 'string'}, {name: 'pairing_name', type: 'string'}, {name: 'pairing_date', type: 'string'}, {name: 'device_name', type:'device_name'} ], validations: [ {type: 'presence', field: 'pairing_key', message : 'A pairing key is required.'}, {type: 'presence', field: 'pairing_name'}, {type: 'presence', field: 'device_name', message : 'A name is required, such as "Family Room"'}, ], proxy: { type: 'localstorage', id : 'avtouch-devices', proxy: { idProperty: 'devices_store' } }, });
-
27 Dec 2010 4:06 PM #3
Hi chwagssd,
thanks for the tip. That worked for me too!
cheers
Francesco
-
27 Dec 2010 8:53 PM #4
Cool
It took me like 4 hours to get to this working point. It's perfect for wipe-all-data needs, but I find it implies a larger problem with the localstorage proxy, since model.save() and store.sync() are not permanently updating the browser's window.localStorage.
Interestingly, if I add, then sync, then update a record, then sync it sticks... but throw a refresh of the browser in there after add and then the update never sticks.
At least this serves as a workaround for the case at hand
-
15 Jan 2011 6:27 AM #5
Hello,
I cannot get this figured out.
here is my code
I need to clear the list before fetching for more data or else the same data can be duplicated in the listCode:touchadmin.processOrdersAjax = { getRecentOrders : function() { var myMask = new Ext.LoadMask(Ext.getBody()); myMask.show(); Ext.Ajax.request({ url: 'http://10.1.1.19/index.php/touchadmin/index/json/', method: 'post', params: {'met':'orders'}, success: function(response, opts) { myMask.hide(); var result = Ext.util.JSON.decode(response.responseText); //console.log(response.responseText); if (!result['error']) { touchadmin.processOrdersAjax.ordersData = result['content'];//Ext.Msg.alert('Success', result['content'], true); touchadmin.processOrdersAjax.insertRecords(); } else { Ext.Msg.alert('Error', result['content'], true); //return false; } }, failure: function(response, opts) { myMask.hide(); console.log(response); //return false; } }); }, insertRecords : function() { var ordersData = touchadmin.processOrdersAjax.ordersData; var totalCount = ordersData['count']; var full = ordersData['full']; var fullCount = full.length; var order; for (i=0; i<fullCount; i++) { order = full[i]; touchadmin.processOrderStore.add({'firstname': order['address']['billing']['firstname'], 'lastname': order['address']['billing']['lastname']}); } // touchadmin.orderStore.add({'firstName': firstname, 'lastName': lastname}); } }; var processOrderModel = Ext.regModel('ProcessOrder', { fields: [{name: 'id', type: 'int'},{name: 'firstname', type:'string'},{name:'lastname', type:'string'}] }); touchadmin.processOrderStoreConfig = { model: 'ProcessOrder', sorters: 'firstname', getGroupString : function(record) { return record.get('firstname')[0]; }, proxy: { type: 'localstorage', id : 'processOrder' }, fields: [{name: 'id', type: 'int'},{name: 'firstname', type:'string'},{name:'lastname', type:'string'}] }; var refreshBtn = new Ext.Button({ disabled: false, ui: 'plain', iconCls: 'refresh', iconMask:true, handler: function() { touchadmin.ProcessOrder.update(''); touchadmin.processOrderStore.getProxy().clear(); touchadmin.processOrderStore.sync(); //touchadmin.ProcessOrder.doLayout(); console.log(touchadmin.processOrderStore); touchadmin.processOrdersAjax.getRecentOrders(); } }); touchadmin.processOrderStore = new Ext.data.Store(touchadmin.processOrderStoreConfig); touchadmin.ProcessOrder = new Ext.Panel({ scroll: 'vertical', layout: Ext.is.Phone ? 'fit' : { type: 'vbox', align: 'center', pack: 'center', }, cls: 'demo-list', items: [{ width: Ext.is.Phone ? undefined : 700, height: Ext.is.Phone ? undefined : 500, xtype: 'list', onItemDisclosure: function(record, btn, index) { //Ext.Msg.alert('Tap', 'Disclose more info for ' + record.get('firstName'), Ext.emptyFn); }, store: touchadmin.processOrderStore, //getRange(0, 9), itemTpl: '<div class="contact"><strong>{firstname}</strong> {lastname}</div>' }], dockedItems: [{ dock: 'bottom', xtype: 'toolbar', items: [refreshBtn, {xtype: 'spacer'}, editBtn] }], listeners: { beforerender: function() { //touchadmin.orderStore.load(); touchadmin.processOrdersAjax.getRecentOrders(); //touchadmin.OrdersAjax.insertRecord(); //Ext.Msg.alert('before render process order'); } } });
-
15 Jan 2011 6:28 AM #6
Hello,
I cannot get this figured out.
here is my code
I need to clear the list before fetching for more data or else the same data can be duplicated in the listCode:touchadmin.processOrdersAjax = { getRecentOrders : function() { var myMask = new Ext.LoadMask(Ext.getBody()); myMask.show(); Ext.Ajax.request({ url: 'http://10.1.1.19/index.php/touchadmin/index/json/', method: 'post', params: {'met':'orders'}, success: function(response, opts) { myMask.hide(); var result = Ext.util.JSON.decode(response.responseText); //console.log(response.responseText); if (!result['error']) { touchadmin.processOrdersAjax.ordersData = result['content'];//Ext.Msg.alert('Success', result['content'], true); touchadmin.processOrdersAjax.insertRecords(); } else { Ext.Msg.alert('Error', result['content'], true); //return false; } }, failure: function(response, opts) { myMask.hide(); console.log(response); //return false; } }); }, insertRecords : function() { var ordersData = touchadmin.processOrdersAjax.ordersData; var totalCount = ordersData['count']; var full = ordersData['full']; var fullCount = full.length; var order; for (i=0; i<fullCount; i++) { order = full[i]; touchadmin.processOrderStore.add({'firstname': order['address']['billing']['firstname'], 'lastname': order['address']['billing']['lastname']}); } // touchadmin.orderStore.add({'firstName': firstname, 'lastName': lastname}); } }; var processOrderModel = Ext.regModel('ProcessOrder', { fields: [{name: 'id', type: 'int'},{name: 'firstname', type:'string'},{name:'lastname', type:'string'}] }); touchadmin.processOrderStoreConfig = { model: 'ProcessOrder', sorters: 'firstname', getGroupString : function(record) { return record.get('firstname')[0]; }, proxy: { type: 'localstorage', id : 'processOrder' }, fields: [{name: 'id', type: 'int'},{name: 'firstname', type:'string'},{name:'lastname', type:'string'}] }; var refreshBtn = new Ext.Button({ disabled: false, ui: 'plain', iconCls: 'refresh', iconMask:true, handler: function() { touchadmin.ProcessOrder.update(''); touchadmin.processOrderStore.getProxy().clear(); touchadmin.processOrderStore.sync(); //touchadmin.ProcessOrder.doLayout(); console.log(touchadmin.processOrderStore); touchadmin.processOrdersAjax.getRecentOrders(); } }); touchadmin.processOrderStore = new Ext.data.Store(touchadmin.processOrderStoreConfig); touchadmin.ProcessOrder = new Ext.Panel({ scroll: 'vertical', layout: Ext.is.Phone ? 'fit' : { type: 'vbox', align: 'center', pack: 'center', }, cls: 'demo-list', items: [{ width: Ext.is.Phone ? undefined : 700, height: Ext.is.Phone ? undefined : 500, xtype: 'list', onItemDisclosure: function(record, btn, index) { //Ext.Msg.alert('Tap', 'Disclose more info for ' + record.get('firstName'), Ext.emptyFn); }, store: touchadmin.processOrderStore, //getRange(0, 9), itemTpl: '<div class="contact"><strong>{firstname}</strong> {lastname}</div>' }], dockedItems: [{ dock: 'bottom', xtype: 'toolbar', items: [refreshBtn, {xtype: 'spacer'}, editBtn] }], listeners: { beforerender: function() { //touchadmin.orderStore.load(); touchadmin.processOrdersAjax.getRecentOrders(); //touchadmin.OrdersAjax.insertRecord(); //Ext.Msg.alert('before render process order'); } } });
-
5 Oct 2011 5:33 AM #7
Follow my blog at: MovableApp.com!
http://twitter.com/#!/movableapp - My Sencha Touch Learning Experience
-
21 Dec 2011 3:46 AM #8
Still Not Working
Still Not Working
I tried the above tutorial, and this still does not work. Any more progress on this issue?
-
7 Feb 2012 9:49 PM #9
try
Code:App.stores.MyStore.data.clear();
-
11 Feb 2013 12:04 PM #10
Data Store Delete All/ Remove All Items
Data Store Delete All/ Remove All Items
If you are using proxy then use,
var store = Ext.getStore('DataStoreName');
store.getProxy().clear();
store.data.clear();
store.sync();
If you are not using proxy then,
var store = Ext.getStore('DataStoreName');
store.removeAll();
store.sync()
Similar Threads
-
[FIXED-878]Ext.ux.DataViewTransition -> remove last items in Store -> staying in view
By tobiu in forum Ext 3.x: BugsReplies: 3Last Post: 8 Jun 2010, 4:19 PM -
[MOVED] Please Implement Delete Key to delete items in addition to Delete Menu Item
By markjlyon in forum Ext Designer: Help & DiscussionReplies: 1Last Post: 11 May 2010, 7:48 AM -
[FIXED][3.x/2.x] Ext.data.Store#remove always fires "remove" event
By mystix in forum Ext 3.x: BugsReplies: 2Last Post: 15 May 2009, 2:19 AM -
Remove single Items from store (plzzzzzzz)
By pomata in forum Ext 2.x: Help & DiscussionReplies: 1Last Post: 1 Feb 2008, 11:17 PM -
Ext.data.Store.remove() does not remove records from modified records array
By phillipL in forum Ext 1.x: BugsReplies: 1Last Post: 29 Jun 2007, 12:40 AM


Reply With Quote