-
13 Dec 2012 1:32 AM #1
[4.2.0] Ext.data.Store.getById() error
[4.2.0] Ext.data.Store.getById() error
I've added into examples/grid/infinite-scroll.js
Code:var grid = Ext.create('Ext.grid.Panel', { ... dockedItems: [{ xtype: "toolbar", dock: "top", items: [{ text: "getById()", handler: function(btn, e) { var grid = btn.up("grid"); grid.getStore().getById(1); } }] }] ... });TypeError: this.data.findBy is not a function
http://localhost/JavaScript/ExtJS/Ex...t-all-debug.js
Line 66104
-
13 Dec 2012 1:55 AM #2
Yes, the backing collection of a buffered store is not a MixedCollection, but a PageMap which should implement the same interface.
Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
13 Dec 2012 2:07 AM #3
Of course getById in this situation would be slow if you have a lot of pages cached.
And will only find the record if it has been read from the server.
buffered stores are sparsely populated. Only pages which are needed to view are loaded, so only pages which have been viewed (or are in the scroll zone around the viewable area) and which have not been purged from the cache will be in there with records available to look up.
Are you taking this into account with your requirement?Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
13 Dec 2012 2:16 AM #4
And the ID field of those records is the forum thread ID, eg "116031", so you'll never find anything using 1
Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
15 Dec 2012 3:36 PM #5
findBy is not a valid option on sparse stores. From 4.2 onwards, it will throw an exception which in debug mode (your built code will not throw)
But if you really have a use case, here's an implementation:
filterBy is valid though. This will be implemented in 4.2 though which was missing before.Code:/** * Returns the first record in this page map which elicits a true return value from the * passed selection function. * @param {Function} fn The selection function to execute for each item. * @param {Mixed} fn.rec The record. * @param {String} fn.key The record's internalId. * @param {Object} scope (optional) The scope (`this` reference) in which the * function is executed. Defaults to this PageMap. * @return {Object} The first record in this page map which returned true from the selection * function, or null if none was found. */ findBy: function(fn, scope) { var me = this, result = null; this.forEach(function(rec) { if (fn.call(scope||me, rec)) { result = rec; return false; } }); return result; },Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
18 Dec 2012 8:19 AM #6
"Yes, the backing collection of a buffered store is not a MixedCollection, but a PageMap which should implement the same interface."
Hi Animal.
But you confirm that this is a bug that should be fixed?
In my project I have a buffered store whose data are displayed by a grid.
Data loading is done without problems, but when later you load the data by an instruction "load" (addRecords: false), I get the same error reported by Ex_Soft too and I get it for the same your observations, namely that the class PageMap does not implement the same interface of MixedCollection class.
Obviously everything works correctly in 4.1.x.
This bug should not be fixed?
Thank you very much in advance.
-
18 Dec 2012 2:59 PM #7
You cannot add records to a buffered store yourself.
A buffered store is a cached map of pages which match the server side dataset.
You cannot use getById reliably because a buffered store only contains a few pages (configurable how many) of the full, server-side dataset. And which pages it has in the cache change as your scroll though.
getById is really meaningless.Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
19 Dec 2012 2:10 AM #8
Hi!
Animal excuse me, but I have not explained the thing well enough. Unfortunately, English is not my native language and I find it hard to express myself properly with it.
Now I'll try to explain better.
My store is a buffered Json Store and retrieve data from the remote server. Hence, the data it contains are not added by me but are required by the server and automatically added.
So, as you rightly say, the data properly "match the server side dataset".
Data from the store are properly displayed by a grid.
So far everything works fine (of course) both in 4.1.x and 4.2.0.
At this point I introduce what for me is a bug.
If you are re-charging programmatically data of the store (for programmatically I mean by the invocation of the instruction "load" of the store, specifying as parameters {addRecords: false}), you get the error reported by Ex_soft.
So, I'm not in any way invoke the instruction "getByID", but only the instruction "load" to reload the data of the store, and this is right, regardless if the store is buffered or not.
While this works in 4.1.x, in 4.2.0 occurs in the reported error.
I really hope that I have explained to you the problem well.
Incidentally, if you try to replicate the same configuration in 4.2.0, you will see that you get the same error, and not because you relied on the instruction "getByID."
I am at your disposal for any clarification.
Thank you very much in advance.
Bye.
-
19 Dec 2012 6:22 AM #9Ext JS Premium Member
- Join Date
- Apr 2008
- Location
- Groningen - Netherlands
- Posts
- 1,017
- Vote Rating
- 23
Ah ..... I used this to check if a record was retrieved from the memoryproxy and loaded in the buffered store. If it was then I did selected it and focused the row.
Code:gridPanel.getStore().guaranteeRange(rowIndex - 40, rowIndex, function(t, e, r) { recordInGrid = gridPanel.getStore().getById(id); if (recordInGrid) { gridPanel.getView().select(recordInGrid); gridPanel.getView().focusRow(recordInGrid); } //if record });
So the function is not worthless for a bufferedstore, you can check if an record exists in the buffer.
Now I am in doubt. I do not need the bufferedstore anymore because I am hoping that Ext.grid.plugin.BufferedRenderer will do the job.
But anyway, backwardscompatibillity is appreciated....and I am feeling like I am loosing grip on that buffered thing.
-
19 Dec 2012 7:17 AM #10
finding by a an anything in a buffered store is, and always was a hit and miss operation.
You can only find records in pages that just by random coincidence HAPPEN to be in the local cache.
There's no backward compatibility thing. findBy in buffered stores has never worked.Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642


Reply With Quote