PDA

View Full Version : Data Store Delete All/ Remove All Items



francescosyd
23 Dec 2010, 6:34 PM
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

chwagssd
27 Dec 2010, 1:50 PM
For me this worked:

deviceStore.getProxy().clear();

Where deviceStore was a

deviceStore = new Ext.data.Store({
model: 'Device',

//autoLoad : true,
});

And the device model was connected to a localstorageproxy


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'
}
},
});

francescosyd
27 Dec 2010, 4:06 PM
Hi chwagssd,

thanks for the tip. That worked for me too!

cheers

Francesco

chwagssd
27 Dec 2010, 8:53 PM
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 ;)

youngilaboungi
15 Jan 2011, 6:27 AM
Hello,

I cannot get this figured out.
here is my code


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');
}
}
});



I need to clear the list before fetching for more data or else the same data can be duplicated in the list

youngilaboungi
15 Jan 2011, 6:28 AM
Hello,

I cannot get this figured out.
here is my code


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');
}
}
});



I need to clear the list before fetching for more data or else the same data can be duplicated in the list

MPeg
5 Oct 2011, 5:33 AM
try read this tutorial:
http://goo.gl/ybwka

StephenTS
21 Dec 2011, 3:46 AM
I tried the above tutorial, and this still does not work. Any more progress on this issue?

Sasha172
7 Feb 2012, 9:49 PM
try


App.stores.MyStore.data.clear();

gendaful
11 Feb 2013, 12:04 PM
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()