PDA

View Full Version : [OPEN-1270] Store#reMap doesn't respect filtered stores



feiichi
20 Sep 2010, 4:29 AM
I've encountered a problem with filtered stores and the Store#reMap method which is called after a new record is inserted into a store and saved.

The problem is it doesn't respect filtered stores, which leads to a nonfunctional Store#getById method:

getById : function(id){
return (this.snapshot || this.data).key(id);
}

As you can see, the method takes in account this.snapshot, but after saving a new record, this is how the this.snapshot.keys referece looks like:

[48, 49, "ext-record-6"]

Compared to this.data.keys:

[48, 49, 50]

Also, when you clear filters with #clearFilter, the data property is replaced by the incorrect snapshot collection.

I've only found one mention of this bug on the forums but with no official answer:
http://www.sencha.com/forum/showthread.php?104269-Store-reMap-method-and-filtered-Stores-BUG

I've also found several other discussions on problems with Store#reMap and DataReader#realize but with no mention of this issue:
http://www.sencha.com/forum/showthread.php?105301-Problem-using-Store.getById()-after-Store.insert
http://www.sencha.com/forum/showthread.php?105442-3.2-OPEN-1158-DataReader.onCreateRecords-doesn-t-reMap-for-mutiple-records
http://www.sencha.com/forum/showthread.php?106052-store-getById-fails-after-record-creation

feiichi
21 Sep 2010, 2:57 AM
In case someone else needs a quick & dirty fix:

Ext.override(Ext.data.Store, {
reMap: function(record) {
if (Ext.isArray(record)) {
for (var i = 0, len = record.length; i < len; i++) {
this.reMap(record[i]);
}
} else {
function alterHashMap(data, record) {
delete data.map[record._phid];
data.map[record.id] = record;
var index = data.keys.indexOf(record._phid);
data.keys.splice(index, 1, record.id);
}
alterHashMap(this.data, record);
if (this.snapshot) {
alterHashMap(this.snapshot, record);
}
delete record._phid;
}
}
});

markmansour
22 Jul 2013, 5:49 PM
Thanks so much feiichi. I just ran into this issue today.

Sencha people. Has this been fixed in later versions of ExtJs (I'm using 3.4.0).