Hybrid View
-
24 Jun 2011 12:25 PM #1
Store findById uses old dataset after second load()
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
-
25 Jun 2011 7:10 AM #2
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:
So, as I said, my quick fix is to override the getById method from:Code:this.snapshot = this.snapshot || this.data.clone();
to:Code:getById : function(id) { return (this.snapshot || this.data).findBy(function(record) { return record.getId() === id; }); },
Code:getById : function(id) { return this.data.findBy(function(record) { return record.getId() === id; }); }
-
25 Jun 2011 8:18 AM #3
Thanks for posting the fix, I use the same solution and it works. Dirty though

-
28 Jan 2012 4:22 AM #4
Oh my! I am so glad I found this, it was driving me up the freaking wall. Thanks for the fix.

-
28 Jan 2012 10:12 PM #5My Book on Sencha Touch - Sencha Touch Cookbook
My Sencha Touch Blog - Walking Tree Sencha Touch Blog
My ExtJS Blog - Walking Tree ExtJS Blog
Active contributor to - Walking Tree's ExtJS and Touch Forums
Buy ExtJS Components from - Walking Tree e-Store
-
29 Jan 2012 3:26 AM #6
-
26 Apr 2012 12:05 PM #7
Hi everybody, I have the same problem when I use
How I can use your fix?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); } } } });
Thanks in advance!
-
27 Apr 2012 12:58 AM #8
To use the fix, you just put that getById function in your store, and it will override the default one.
-
27 Apr 2012 12:51 PM #9
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:
I'm not pretty sure what I have to do. Still not working.Code:var repartoStore = new Ext.data.Store ({ autoLoad: true, model: 'repartoModel', filter : function(id) { return this.data.findBy(function(record) { return record.getId() === id; }); } });
Thanks for your time.
Thank you for reporting this bug. We will make it our priority to review this report.


Reply With Quote
