PDA

View Full Version : Add filters to a Ext.data.Store



Totom
8 Jun 2012, 1:59 AM
Hi, I have a store defined as:



this.storeEvents = Ext.create('Ext.data.Store',
{
model: 'ts.model.datex2event'
,proxy:
{
type: 'ajax',
url : Optima.wfsUrl(this.serviceUrls[this.mode]),
filterParam: undefined,
reader:
{
type: 'json'
,root: 'features'
,record: 'properties'
}
}
,autoLoad: false
,remoteFilter: false

,filters:
[
new Ext.util.Filter(
{
filterFn: this.filterFunctions[this.mode] // return always false;
})
]

});


The store is used in a gridview.
The problem I'm facing is that even if the filterFunction is invoked (I checked with a console.info() inside the function), all the models are inserted in the store, even if the function returns false, so the grid is populated with elements that I don't want....
Someone has any ideas of what I'm doing wrong?

scottmartin
8 Jun 2012, 10:52 AM
create a load listener on your store and use store.filter(..)

Scott.

Totom
10 Jun 2012, 11:48 PM
I solved with this:



this.storeEvents.load(
{
scope : this.storeEvents,
callback: function (myGridWindow)
{
return function(records, operation, success)
{
// Items to remove
var eventsToRemove = [];
Ext.each(records, function(model, index)
{
var isOk = myGridWindow.filterFunctions[myGridWindow.mode](model);
if(!isOk)
{
eventsToRemove.push(model);
}
});

this.remove(eventsToRemove);
}
}(myself)

});


I really don't like this type of workaround (maybe use the onLoad event is nicer).
But the "filters" what are meant for? Why functions are called, but the filtered items are not removed from the store?