PDA

View Full Version : SimpleStore.filterBy not filtering



dbadke
2 May 2007, 1:41 PM
Ext 1.0.1a

I have a grid with a SimpleStore. Applying a filterBy to the store is not working. My code:

this.dataStore = new Ext.data.SimpleStore(
{fields: ['id', 'title', 'canDelete', 'updateStatus'],
data : [...]});
this.dataStore.filterBy(function(record, id) {return (record.get('updateStatus') != 'd')});
Looking at the Ext.data.store filterBy code in Firebug, I see this:

http://lettuce.tapor.uvic.ca/~dbadke/img/screenshot4.jpg

The 'data' variable is being set to this.snapshot or this.data. Firebug shows that this.data has items, and this.snapshot does not, yet the 'data' variable has been set to this.snapshot (see the inset in the image above). Of course there is no data there to filter, so nothing happens.

So... am I doing something silly? :"> Or misunderstanding the filterBy code? :-/ Or is this possibly a bug? :-?

tryanDLS
2 May 2007, 1:52 PM
Well that check is for existence, not whether there's >0 rows. So if snapshot is an empty array, it will still get assigned to data. It's only null the first time you call filterBy or if you call clearFilter

dbadke
2 May 2007, 2:12 PM
The problem is that this.snapshot is being set to var data, which has just been set to this.snapshot. So if this.snapshot is empty the first time through, it will continue to be empty every time after that, and so will be this.data - calling clearFilter just puts the empty this.snapshot into this.data, which doesn't help. Seems to me that this.snapshot should be initialized to null when the store is initialized, or that there needs to be a check for an empty this.snapshot, like:

filterBy : function(fn, scope){
var data = (this.snapshot.length > 0) ? this.snapshot : this.data;
this.snapshot = data;
this.data = data.filterBy(fn, scope);
this.fireEvent("datachanged", this);
},

I am assuming that the intent is to clear the existing filter before applying a new one; problem is, if there is no previous filter to clear, the var data = this.snapshot || this.data; line can't detect it.

dbadke
2 May 2007, 2:20 PM
:"> :"> :"> :">
:"> OOPS! :">
:"> :"> :"> :">

My bad... right after I posted that last thing, I discovered the problem: I had a stray filterBy call being executed before the store had any data loaded, so of course everything was empty! Getting rid of that silly filterBy fixed it.

Still, maybe the check for an empty snapshot wouldn't hurt...