Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing records that exist in an array from ExtJS store

Tags:

extjs

extjs4.2

I have a store and an array. I want to remove records from the store if that record's value matches with values in the array. Following is is the code I am trying but it's not working. Can anyone suggest the correct way?

'store' is the actual store and 'filterItems' is the array of records I want to remove from 'store'.

    store.each(function (record) {
        for (var i = 0; i < filterItems.length; i++) {
            if (record.get('ItemId') === _filterItems[i].get('ItemId')) {
                itemIndex = store.data.indexOf(record);
                store.removeAt(itemIndex );
            }
        }
    });
like image 359
user1640256 Avatar asked Aug 13 '14 10:08

user1640256


People also ask

How to remove record from store in ExtJS?

columnId == columnId) { indexes[i++] = index; } } }, this); dataviewStore. remove(indexes); this is my example if your record is matches with the value then store the index of that item after storing indexes of all the items and remove them. Otherwise you have to use for loop and remove them from end of the array.

What is store in Ext JS?

The Store class encapsulates a client side cache of Ext. data. Model objects. Stores load data via a Ext. data.


1 Answers

Not sure about your code because i dont know all variables. Though its recommended to use the store.getRange() fn and iterate the array via for loop. Its better for performance.

var storeItems = store.getRange(),
    i = 0;

for(; i<storeItems.length; i++){     
   if(Ext.Array.contains(filterItemIds, storeItems[i].get('id')))
      store.remove(store.getById(storeItems[i].get('id')));            
} 

Here is an example which i tried right now and it works well.

https://fiddle.sencha.com/#fiddle/8r2

like image 169
JuHwon Avatar answered Oct 12 '22 07:10

JuHwon