PDA

View Full Version : Store isFiltered always returns true when snapshot exists



art.dev.ext
18 Jul 2011, 7:11 AM
Sencha Touch version tested:

1.1.0


Platform tested against:

Windows XP


Description:

When store.snapshot does not exists, isFiltered() always returns false
When store.snapshot exists, isFiltered() always returns true


Test Case:



// declare a "equals" function
Ext.util.MixedCollection.prototype.equals=function(mixedCol){
if ((!mixedCol) || (mixedCol.getCount() != this.getCount())) return false;
for(var i = 0, len = this.items.length; i < len; i++){
if ((this.keys[i] != mixedCol.keys[i]) || (this.items[i] != mixedCol.items[i])){
return false;
}
}
return true;
}
Ext.regModel('MyModel',{fields:['name']});

console.log("Here is Ext.data.Store.isFiltered function :");
console.log("isFiltered : function() {");
console.log(" return !!this.snapshot && this.snapshot != this.data;");
console.log("}");
console.log('initializing store with data:[{name:"myname"},{name:"yourname"}] ');
var s = new Ext.data.Store({
model:"MyModel",
data:[{name:"myname"},{name:"yourname"}]
});
console.log("store.isFiltered() is " + s.isFiltered() ); // => false
console.log("because !!this.snapshot is " + (!!s.snapshot)); // => false
console.log("If we filter by returning true (means no filter is applied),");
s.filterBy(function(){return true;});
console.log("store.isFiltered() is " + s.isFiltered() ); // => true
console.error("because snapshot != data is " + (s.snapshot != s.data)); // => true
console.log("whereas custom function !data.equals(snapshot) returns " + (!s.data.equals(s.snapshot))); // => false
Since store.snapshot is a clone of store.data, (this.snapshot != this.data) is always true

Debugging already done:

sencha-touch-debug.js (line 7168)
isFiltered : function() {
return !!this.snapshot && this.snapshot != this.data;
}


Possible fix:

Ext.util.MixedCollection.prototype.equals=function(mixedCol){
if ((!mixedCol) || (mixedCol.getCount() != this.getCount())) return false;
for(var i = 0, len = this.items.length; i < len; i++){
if ((this.keys[i] != mixedCol.keys[i]) || (this.items[i] != mixedCol.items[i])){
return false;
}
}
return true;
}
Ext.override(Ext.data.Store, {
isFiltered : function() {
return !!this.snapshot && this.data.equals(this.snapshot);
}
});