Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to remove multiple records from store? extjs

What is the best way to remove multiple records with a condition in extjs?

For example:

var store = Ext.create('Ext.data.Store', {
    data: [
        {name: 'Ed', age: 21},
        {name: 'Tommy', age: 15},
        {name: 'Aaron', age: 18},
        {name: 'John', age: 22}
    ]
});

I want to remove records which are 'age' is less than 20(In this case, 'Tommy' and 'Aaron'). This question could be same as how to find multiple records which much a condition.

like image 677
Kohei Mikami Avatar asked Dec 25 '22 10:12

Kohei Mikami


1 Answers

Using just the public API and keeping in mind that you probably won't want to filter the store directly or remove items one-by-one as this will trigger unnecessary redraws on any connected UI components - you could use the following:

var subCollection = store.getData().createFiltered(function(item){
    return item.get('age') < 20;
});

store.remove(subCollection.getRange());
like image 104
Emissary Avatar answered Dec 28 '22 23:12

Emissary