Thank you for reporting this bug. We will make it our priority to review this report.
-
Sencha User
Store findById uses old dataset after second load()
TLDR: findById() does not work after different dataset is loaded into store.
Given the following situation:
(1) Create a datastore and set an arbitrary filter upon instatiation
(2) load() a dataset through a json-proxy
(3) retrieve arbitrary record via store.findById() -> returns the correct record
(4) change the url-parameters of the corresponding proxy to fetch a slightly different dataset
(5) load() the "different" dataset
(6) store.findById() does not return the correct record in the new dataset. Instead, it returns the corresponding record from the previous dataset.
I investigated the issue and found that store.findById() works on either the actual dataset or a snapshot (this.data vs. this.snapshot in the source). The second load() command (see 5) probably does not correctly reset the snapshot of data.
Best
Philipp
-
Sencha User
I have the same issue, I've just override the getById method on Store instance to not use snapshot and that fixed the problem, at least as a quick workaround.
I think it has to do with snapshot, when filter method is called on the second load (no matter if you have added a filter or not) this.snapshot is a valid object but whit wrong data and this line makes the difference:
Code:
this.snapshot = this.snapshot || this.data.clone();
So, as I said, my quick fix is to override the getById method from:
Code:
getById : function(id) {
return (this.snapshot || this.data).findBy(function(record) {
return record.getId() === id;
});
},
to:
Code:
getById : function(id) {
return this.data.findBy(function(record) {
return record.getId() === id;
});
}
-
Sencha User
Thanks for posting the fix, I use the same solution and it works. Dirty though
-
Sencha User
Oh my! I am so glad I found this, it was driving me up the freaking wall. Thanks for the fix.
-
Sencha Premium Member

Originally Posted by
schtono
TLDR: findById() does not work after different dataset is loaded into store.
Given the following situation:
(1) Create a datastore and set an arbitrary filter upon instatiation
(2) load() a dataset through a json-proxy
(3) retrieve arbitrary record via store.findById() -> returns the correct record
(4) change the url-parameters of the corresponding proxy to fetch a slightly different dataset
(5) load() the "different" dataset
(6) store.findById() does not return the correct record in the new dataset. Instead, it returns the corresponding record from the previous dataset.
I investigated the issue and found that store.findById() works on either the actual dataset or a snapshot (this.data vs. this.snapshot in the source). The second load() command (see 5) probably does not correctly reset the snapshot of data.
Best
Philipp
Please paste an example code to reproduce this problem!
-
Sencha User
-
Sencha User
Hi everybody, I have the same problem when I use
Code:
var listaDetDoc = new Ext.List({
id: 'listaDetDoc',
store: detalleMaterialStore,
itemTpl:
'<div>
'<span class="list-izq">{Posicion} - {CodMaterialCorto}</span>'+
'</div>',
listeners: {
'render': function (thisComponent) {
thisComponent.getStore().load();
if(detalleMaterialStore.last()){
var doc = listaDetDocPanel.getRecord().data.id;
thisComponent.getStore().filter('idDoc',doc);
}
}
}
});
How I can use your fix?
Thanks in advance!
-
Sencha User
To use the fix, you just put that getById function in your store, and it will override the default one.
-
Sencha User
Hi Travisrowland, I did what you said, but doesn't work, I think is because the original method of this post is getById() but I'm using filter(), in my case I think will be like this:
Code:
var repartoStore = new Ext.data.Store ({
autoLoad: true,
model: 'repartoModel',
filter : function(id) {
return this.data.findBy(function(record) {
return record.getId() === id;
});
}
});
I'm not pretty sure what I have to do. Still not working.
Thanks for your time.