0
votes

I have a store filled on application init.

It is used in multiselect combobox in a view where I select records that I want and add their id's to a variable.

In grid I have a combobox with the same store, and I want to filter out store so it only contains the id's I have selected.

setViewData : function(dataStore, record, readOnly) {

    var store = Ext.getStore('ScaleStore');
        store.clearFilter();

    store.filterBy(function (scaleRecord) {
        Ext.each(record.data.scaleList, function (scale) {
            if(scale.id == scaleRecord.data.schl1NrId) {                    
                return true;
            }
        });

    });
}

The store contains 5 records.

record.data.scaleList - here I have lets say 3 records out of 5 I have selected in the multiselect combobox.

My goal is to have only the ones I have selected(3 out of 5) displayed in the grid combobox. With this code I get all of the records, or wrong ones at random.

Any pointers to what I am doing wrong here?

Thank you all :)

1

1 Answers

0
votes

It seems you are using Ext.each incorrectly. The documentation on Ext.each states the following:

The iteration can be stopped by returning false from the callback function. Returning undefined (i.e return;) will only exit the callback function and proceed with the next iteration of the loop.

Which means you are not returning the values that you want to filter. To do so, and assuming that you still want to use Ext.each, you would have to do the following:

store.filterBy(function (scaleRecord) { // This function is executed
                                        // for each record
    var filter = false;

    Ext.each(record.data.scaleList, function (scale) {
        if(scale.id == scaleRecord.data.schl1NrId) {
            filter = true;

            return false; // return false if you want to stop the iteration
        }
    });

    return filter; // return the boolean to apply the
                   // filter to the current record
});