PDA

View Full Version : [CLOSED] How to apply filterBy() on already filtered store in Grid



PriceRightHTML5team
Aug 06, 2013, 10:00 AM
Hi,

I have a filtered store with some values.

Again I need to apply another filter on that already filtered store.

e.g.

Store has following values
1) User1
2) User1
3) User1
4) User22
5) User3
6) User4
7) User4
8) User51
9) User52

Filtered store :
1) User1
7) User4
9) User52

I need to apply filter on above store.

Condition is record not equal to 'User52'

Output should be :
1) User1
7) User4

Code used for above filtering :



var store = App.GridPanel.getStore();
var length = store.data.items.length;
if (length === store.totalCount) {
store.filterBy(function (record) {
if(record.get('UserName') != givenValue)
return true;
else
return false;
});
}

else if (length > 0) {
store.data.items.filter(function (record) {
for (var i = 0; i < length; i++) {
if (record.get('UserName') != givenValue)
return true;
else
return false;
}
});
}



Above code is not giving us expected output.

Please suggest the way to implement this.

Daniil
Aug 06, 2013, 1:47 PM
Hi @PriceRightHTML5team,

Please try this override and use the filterRestBy method instead of the filterBy one.

filterRestBy

Ext.data.Store.override({
filterRestBy: function (fn, scope) {
var me = this;

me.snapshot = me.snapshot || me.data.clone();
me.data = me.queryRestBy(fn, scope || me);
me.fireEvent('datachanged', me);
me.fireEvent('refresh', me);
},

queryRestBy: function (fn, scope) {
var me = this;

return me.data.filterBy(fn, scope || me);
}
});