1. #11
    Touch Premium Member
    Join Date
    Jul 2011
    Location
    Helsinki, Finland
    Posts
    71
    Vote Rating
    0
    kortsi is on a distinguished road

      0  

    Default


    Quote Originally Posted by tvanzoelen View Post
    I filter my data in the callback of a load. Why filter data if the store isn't loaded yet?
    I can't load all the data because there are thousands or even millions of rows in some tables. I must apply filtering before loading. That way I only need to fetch that one row, or some subset of rows from the database...

    Edit: I'm using remote filtering, of course

  2. #12
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,625
    Vote Rating
    331
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      0  

    Default


    I gave this a go but I couldn't reproduce the problem. My test case is below, you can try it yourself. I tried it with an Ajax proxy too but the result was the same.

    One observation I made is that the call to filter initiates an HTTP request, as well as the call to load, so you're making twice as many requests as you need.

    Code:
    Ext.onReady(function() {
        function createStore() {
            return new Ext.data.Store({
                fields: ['title'],
                remoteFilter: true,
                proxy: {
                    type: 'jsonp',
                    url: 'http://www.sencha.com/forum/topics-browse-remote.php',
                    reader: {
                        root: 'topics',
                        totalProperty: 'totalCount'
                    }
                }
            });
        }
    
        var stores = [createStore(), createStore(), createStore()];
    
        for (var index = 0 ; index < 3 ; index++) {
            var store = stores[index];
    
            store.filter({
                property: 'title',
                value: 'grid'
            });
    
            store.load({
                scope: store,
                callback: function() {
                    console.log('Loaded');
                    console.log(this.getCount());
                }
            });
        }
    });

  3. #13
    Touch Premium Member
    Join Date
    Jul 2011
    Location
    Helsinki, Finland
    Posts
    71
    Vote Rating
    0
    kortsi is on a distinguished road

      0  

    Default


    Quote Originally Posted by skirtle View Post
    I gave this a go but I couldn't reproduce the problem. My test case is below, you can try it yourself. I tried it with an Ajax proxy too but the result was the same.

    One observation I made is that the call to filter initiates an HTTP request, as well as the call to load, so you're making twice as many requests as you need.
    Thanks! I found that out as well while looking at the code. I actually changed my code to look like this:

    Code:
    for (var i in stores) {
      var store = stores[i];
    
      // Clear all previous filters
      store.filters.clear();
    
      // Filter and load
      var decoded = store.decodeFilters(
          {
            property: storedFormManager.filterProperty,
            value:    storedFormManager.filterId
          }),
          length = decoded.length;
    
      for (var i = 0; i<length; i++) {
        store.filters.replace(decoded[i]);
      }
    
      store.load({     
        scope:    {       
          store: store,        
          manager: storedFormManager     
        },     
        callback:   storeLoaded   
      }); 
    }
    The new filter code (bold) is basicly copied from the Store.filter() method, but without the subsequent load(). Using this bit, my callbacks started firing, and now the data is only loaded once.

    The Store class seems to miss a method that could be used to just apply a filter without loading immediately. It could also be an option...

  4. #14
    Ext JS Premium Member
    Join Date
    Jun 2010
    Posts
    73
    Vote Rating
    0
    optima is on a distinguished road

      0  

    Default


    please ignore
    Last edited by optima; 5 Jun 2012 at 4:29 AM. Reason: silly mistake