1. #1
    Sencha User
    Join Date
    Mar 2010
    Posts
    249
    Vote Rating
    1
    Ex_Soft is an unknown quantity at this point

      0  

    Default [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

  2. #2
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,505
    Vote Rating
    53
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Yes, the backing collection of a buffered store is not a MixedCollection, but a PageMap which should implement the same interface.


  3. #3
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,505
    Vote Rating
    53
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    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?

  4. #4
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,505
    Vote Rating
    53
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    And the ID field of those records is the forum thread ID, eg "116031", so you'll never find anything using 1

  5. #5
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,505
    Vote Rating
    53
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    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:

    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;
            },
    filterBy is valid though. This will be implemented in 4.2 though which was missing before.

  6. #6
    Sencha User
    Join Date
    Mar 2010
    Posts
    24
    Vote Rating
    3
    ElCondor1969 is on a distinguished road

      0  

    Default


    "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.

  7. #7
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,505
    Vote Rating
    53
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    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.

  8. #8
    Sencha User
    Join Date
    Mar 2010
    Posts
    24
    Vote Rating
    3
    ElCondor1969 is on a distinguished road

      0  

    Default


    Quote Originally Posted by Animal View Post
    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.
    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.

  9. #9
    Ext JS Premium Member tvanzoelen's Avatar
    Join Date
    Apr 2008
    Location
    Groningen - Netherlands
    Posts
    1,114
    Vote Rating
    30
    tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about

      0  

    Default


    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.

  10. #10
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,505
    Vote Rating
    53
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    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.