You found a bug! We've classified it as a bug in our system. We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.
  1. #1
    Ext JS Premium Member SimonFlack's Avatar
    Join Date
    Jul 2010
    Location
    Norway
    Posts
    241
    Vote Rating
    3
    SimonFlack is on a distinguished road

      0  

    Default [TOUCH-428] Store.snapshot contains corrupt data.

    [TOUCH-428] Store.snapshot contains corrupt data.


    Sencha Touch version tested:
    • 1.0.1a
    • only default ext-all.css

    Description:
    • Store snapshot is corrupt after changing a proxies data source and reloading the store.
    • Similar problems also happen if using paging. Clearing the filter causes the first page to be reloaded into the store from the snapshot.

    Code:
    clearFilter : function(suppressEvent) {
            this.filters.clear();
            
            if (this.isFiltered()) {
                this.data = this.snapshot.clone();
                delete this.snapshot;
    
                if (suppressEvent !== true) {
                    this.fireEvent('datachanged', this);
                }
            }
        },
    Test Case:

    Code:
        
    Ext.regModel('SomeModel', {fields: ['name']});
    
    var myProxy = new Ext.data.MemoryProxy({
    	type: 'memory',
    	reader: {
    		type: 'json',
    		root: 'root'
    	}
    });
    
    var data1 = {
    	root: [
    		{name: 'One'},
    		{name: 'Two'},
    	]
    };
    
    var data2 = {
    	root: [
    		{name: 'Cat'},
    		{name: 'Dog'},
    		{name: 'Fish'}
    	]
    };
    
    var myStore = new Ext.data.Store({
    	model: 'SomeModel',
    	proxy: myProxy
    	 
    });
    	
    	//Setup 
    Ext.setup({
        icon: 'icon.png',
        glossOnIcon: false,
        onReady: function() {
    	
    		var myList = new Ext.List({
    			id: 'theList',
    			fullscreen: true,
    			itemTpl : '{name}',
    			store: myStore
    		});
    			
    	}
    });

    Steps to reproduce the problem: (In Console)
    • Ext.getCmp('theList').store.proxy.data = data1
    • Ext.getCmp('theList').store.load()
    • Ext.getCmp('theList').store.proxy.data = data2
    • Ext.getCmp('theList').store.load()
    • Ext.getCmp('theList').store.filter('name', 'Fish')
    • Ext.getCmp('theList').store.clearFilter()

    The result that was expected:
    • One, Two ( After first load() )
    • Cat, Dog, Fish ( After second load() )
    • Fish ( After filtering)
    • Cat, Dog, Fish ( After clearFilter())

    The result that occurs instead:
    • One, Two ( After first load() )
    • Cat, Dog, Fish ( After second load() )
    • Fish ( After filtering)
    • One, Two ( After clearFilter() )

    Screenshot or Video:


    Possible fix:
    • Update the Store's snapshot when proxies data is changed. For example if the application changes the "url" of a RESTProxy and then reloads the store the snapshot shoult contain this new data and not the data from the original loaded data.
    Last edited by SimonFlack; 11 Jan 2011 at 3:02 AM. Reason: Added sencha version

  2. #2
    Touch Premium Member
    Join Date
    Sep 2010
    Location
    Norway
    Posts
    14
    Vote Rating
    0
    oyvinht is on a distinguished road

      0  

    Default


    I can verify that adding:

    someStore.on('load', function (store) {
    store.snapshot = store.data;
    });

    makes filtering/clearing work as desired.

    --
    Oyvin

  3. #3
    Sencha User d5chris's Avatar
    Join Date
    Feb 2011
    Location
    Sydney
    Posts
    59
    Vote Rating
    2
    d5chris is on a distinguished road

      0  

    Default


    Me too having a problem with this bug:

    http://www.sencha.com/forum/showthre...460#post581460

    Please fix.

    Our team also has a paid support account under the name 'pdiemert' FWIW.

  4. #4
    Sencha User
    Join Date
    Feb 2011
    Posts
    21
    Vote Rating
    0
    ostkaka is on a distinguished road

      0  

    Default


    The bug is still present in 1.1

    For some reason oyvinht's fix didn't work for me so I added the following code to the loadRecords function.

    Code:
       this.data = this.snapshot.clone();
       delete this.snapshot;
       this.fireEvent('datachanged', this);

  5. #5
    Sencha User jep's Avatar
    Join Date
    Sep 2010
    Posts
    862
    Vote Rating
    21
    jep will become famous soon enough jep will become famous soon enough

      0  

    Default


    Very frustrating problem. Seems like a flaw in some of the rather basic core functionality of a store.

  6. #6

  7. #7
    Ext JS Premium Member anselmtmcclain's Avatar
    Join Date
    Mar 2008
    Location
    Northern California
    Posts
    84
    Vote Rating
    3
    anselmtmcclain is on a distinguished road

      0  

    Default Override to Ext.data.Store.loadRecords()

    Override to Ext.data.Store.loadRecords()


    We added this override (the line below the big starred comment) to delete the snapshot. Not thoroughly tested by any means but seems to solve the issues we were having. Any feedback?

    Bizarre that this has not been fixed. Thanks - ATM

    Code:
    Ext.override(Ext.data.Store, {
        loadRecords: function(records, add) {
               if (!add) {
                   this.data.clear();
               }
    
               this.data.addAll(records);
               // ***************************************************************
               // As of Touch 1.1 the snapshot is not updated/cleared properly on data load.
               // ***************************************************************
               if (this.snapshot) delete this.snapshot;
    
               for (var i = 0, length = records.length; i < length; i++) {
                   records[i].needsAdd = false;
                   records[i].join(this);
               }
    
               this.suspendEvents();
    
               if (this.filterOnLoad && !this.remoteFilter) {
                   this.filter();
               }
    
               if (this.sortOnLoad && !this.remoteSort) {
                   this.sort();
               }
    
               this.resumeEvents();
               this.fireEvent('datachanged', this, records);
           }
    });

  8. #8
    Touch Premium Member
    Join Date
    Aug 2010
    Location
    New York, NY
    Posts
    66
    Vote Rating
    1
    sandeep45 is on a distinguished road

      0  

    Default store snapshot has wrong data

    store snapshot has wrong data


    I am reloading the store by changing its proxies url and then calling load. Now although store.data has the correct data, store.snapshot.data has the wrong data.

  9. #9
    Sencha - Support Team mike.estes's Avatar
    Join Date
    Mar 2011
    Location
    Redwood City, CA
    Posts
    221
    Vote Rating
    9
    mike.estes will become famous soon enough

      0  

    Default


    I've modified this thread to reflect the correct bug id

  10. #10
    Sencha User
    Join Date
    Jul 2011
    Posts
    7
    Vote Rating
    0
    fox1charlie is on a distinguished road

      0  

    Default


    I have the same problem.
    The override specified above fixes it though.

Similar Threads

  1. Snapshot in Store
    By harsha_velicheti in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 6 Feb 2012, 8:32 AM
  2. [OPEN] [TOUCH-428] Ext.data.Store loadData does not clear / remove snapshot
    By buz in forum Sencha Touch 1.x: Bugs
    Replies: 6
    Last Post: 26 Aug 2011, 3:47 PM
  3. Grid Store snapshot
    By taxidriver in forum Ext 3.x: Help & Discussion
    Replies: 6
    Last Post: 11 Jan 2011, 4:40 AM
  4. Replies: 1
    Last Post: 12 Mar 2010, 4:17 PM
  5. [2.0b1][CLOSED] Ext.data.Store.insert misses to update snapshot
    By andrei.neculau in forum Ext 2.x: Bugs
    Replies: 6
    Last Post: 22 Sep 2009, 11:15 PM

Thread Participants: 11