PDA

View Full Version : Remove several data in once from a store



marxan
22 Aug 2012, 11:35 PM
Hello,

I have several multi-select combos that are used to load data in my grid. This works fine, now what I'm trying to do is to remove the data from the store when I unselect a value from the combo.

So I need to find in my store what data match the value of my store.

This is the code I've written so far:


for (i= 0; i< storeSize;i++){ model = store.findExact("CODEFC",valueToRemove);
store.removeAt(model);
}

The problem is when I have a lot of raws in the grid, this functionnality starts to be very slow because the find Exact only the first matched.

I haven't found any method that could return all the match of the store. If it exists I would'nt need to do this loop and I guess it will be fast or at least acceptable to use this functionnality.

Thanks in advance for any help.

vietits
23 Aug 2012, 12:06 AM
Try this:


for(var i = store.getCount() - 1; i > -1; i--){
var record = store.getAt(i);
if(record.get("CODEFC") == valueToRemove){
store.removeAt(i);
}
}

marxan
23 Aug 2012, 12:38 AM
Thanks for your quick answer but unfortunately it has the same problem as my code, it does what it needs to do but I have the brower not responding for while when I execute it. I thought that accessing a store was faster than this...

redraid
23 Aug 2012, 12:53 AM
var toRemove = [];

store.each(function (record) {
if (record.get('CODEFC') === valueToRemove) {
toRemove.push(model);
}
});
store.remove(toRemove);

marxan
23 Aug 2012, 1:28 AM
Thanks!



var toRemove = [];

store.each(function (record) {
if (record.get('CODEFC') === valueToRemove) {
toRemove.push(model);
}
});
store.remove(toRemove);

marxan
23 Aug 2012, 5:20 AM
Somthing weird happened, the code you gave me worked fine until I cleaned some code and now I have an error that model is not defined... Any idea? I guess it was defined before I cleaned it but it's not mentioned in the code you sent me.



removeRecord: function (c,record,index,e){

if(Global.codefc != '') {
valueToRemove = record.get("CODEFC");

if (Global.indicatorGroup == 'TRAPS')
{
var store = Ext.getStore('MetrSeriesDisplayedStore');
}
else if (Global.indicatorGroup == 'NRR')
{
var store = Ext.getStore('NrrSeriesStore');
}





var toRemove = [];
store.each(function (record) {
if (record.get('CODEFC') === valueToRemove) {
toRemove.push(model);
}
});
store.remove(toRemove);
}
}

redraid
23 Aug 2012, 5:27 AM
which line throws the error?

marxan
23 Aug 2012, 5:56 AM
toRemove.push(model);

redraid
23 Aug 2012, 6:30 AM
In callback function param name "record", you push to array undefined var "model"

store.each(function (record) {
if (record.get('CODEFC') === valueToRemove) {
//toRemove.push(model);// wrong
toRemove.push(record);// correct
}
});

marxan
23 Aug 2012, 6:35 AM
Thanks, it was indeed the issue. I think it worked before because I kept my previous code and model was defined before.