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:

  • ExtJS vs. jQueryUI
  • Extjs store.load does not make the call
  • get a row from a grid ExtJs 4
  • ExtJS - Loop through CheckBoxGroup
  • Read-only combo box in EXT JS
  • How to set tooltip for treelist in ExtJS?
  • 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.

  • Equivalent of jQuery getScript() in ExtJS?
  • Application messed up on keyboard pop-up
  • Simple swipe gallery with jQTouch javascript iphone / ipad
  • Add help button to Extjs gridpanel header
  • EXT JS custom TreeNodeUI or XTemplate
  • ExtJs How do I scroll to the bottom of a grid?
  • 4 Solutions collect form web for “What is the best way to remove multiple records from store? extjs”

    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());
    

    You probably don’t want removeAll, but just to iterate and remove the ones that match

    for ( var i = store.data.length; i--; ) {
        if ( store.data[i].age > 20 ) store.removeAt(i);
    }
    
    store.remove(
        store.queryBy(function(record) {
            ...
        }).getRange()
    )
    

    works in 4, 5 and 6.

    Another approach:

    // get records..
    
            records.forEach(function (record) {
                if (record.getData().age < 20) {
                    store.remove(record);
                }
            });