1. #1
    Sencha Premium Member Wedgie's Avatar
    Join Date
    Jan 2009
    Location
    Melbourne, Australia
    Posts
    76
    Vote Rating
    0
    Answers
    1
    Wedgie is on a distinguished road

      0  

    Default Answered: How to change filter on Ext.data.Store without causing re-load

    Answered: How to change filter on Ext.data.Store without causing re-load


    On Ext 4.0.7 with Ext Designer 1.2.2

    The filter() method on Ext.data.Store keeps adding new filters with each call. I don't want it to do that so I call clearFilter() first. But this causes the store to load the data, and then it loads it again when I call filter(). This happens even with the autoload config not set. Here is my Store as created by Ext Designer

    Code:
    Ext.define('MyApp.store.RequestListStoreForSearch', {
        extend: 'Ext.data.Store',
        constructor: function(cfg) {
            var me = this;
            cfg = cfg || {};
            me.callParent([Ext.apply({
                storeId: 'requestListStoreForSearch',
                pageSize: 10,
                remoteFilter: true,
                remoteGroup: true,
                remoteSort: true,
                proxy: {
                    type: 'ajax',
                    simpleSortMode: true,
                    url: '../spring/request/list',
                    reader: {
                        type: 'array',
                        root: 'data'
                    }
                },
                fields: [ ...
                ]
            }, cfg)]);
        }
    });
    If I call this:
    Code:
     
          store.clearFilter();
          store.filter(filters);
          store.load();
    The store gets loaded for each call, with a race as to which one gets the remote data first/last.

    So how do I set and change filters dynamically please?

  2. This is the definition of clearFilter methods:
    Code:
    clearFilter: function(suppressEvent) {
            var me = this;
    
            me.filters.clear();
    
            if (me.remoteFilter) {
                me.load();
            } else if (me.isFiltered()) {
                me.data = me.snapshot.clone();
                delete me.snapshot;
    
                if (suppressEvent !== true) {
                    me.fireEvent('datachanged', me);
                }
            }
        },
    If you use it remotely, it only calls me.filters.clear(), and then me.load();. The docs expose filters as a property of datastore, so you should be fine doing

    Code:
    store.filters.clear(); //clear filters without loading store
    Or, like you said, you can temporarily disabled remoteFilter
    Code:
    store.remoteFilter = false;
    store.clearFilter();
    store.remoteFilter = true;
    Doesn't look really nice, but it works at the moment.

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,582
    Vote Rating
    433
    Answers
    3102
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    If you have remoteFilter set to true it will always send a new call to the server when you filter the store.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    http://www.JSONPLint.com - Source to lint your JSONP!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!

    When posting code, please use BBCode's CODE tags.

  4. #3
    Sencha Premium Member Wedgie's Avatar
    Join Date
    Jan 2009
    Location
    Melbourne, Australia
    Posts
    76
    Vote Rating
    0
    Answers
    1
    Wedgie is on a distinguished road

      0  

    Default


    Thanks Mitchell

    The result set would be too big without filters so I need them to be applied remotely, but I also need to change them dynamically so that the user can perform searching. What is the method for doing this without causing two asynchronous loads to be done, one for clearFilter() and one for filter()

    Is there perhaps a way to turn off remoteFilter temporarily while I call clearFilter()? I can't see a method in the docs for that.

  5. #4
    Sencha - Services Team bt_bruno's Avatar
    Join Date
    Mar 2008
    Location
    Redwood City, CA
    Posts
    145
    Vote Rating
    7
    Answers
    10
    bt_bruno is on a distinguished road

      0  

    Default


    This is the definition of clearFilter methods:
    Code:
    clearFilter: function(suppressEvent) {
            var me = this;
    
            me.filters.clear();
    
            if (me.remoteFilter) {
                me.load();
            } else if (me.isFiltered()) {
                me.data = me.snapshot.clone();
                delete me.snapshot;
    
                if (suppressEvent !== true) {
                    me.fireEvent('datachanged', me);
                }
            }
        },
    If you use it remotely, it only calls me.filters.clear(), and then me.load();. The docs expose filters as a property of datastore, so you should be fine doing

    Code:
    store.filters.clear(); //clear filters without loading store
    Or, like you said, you can temporarily disabled remoteFilter
    Code:
    store.remoteFilter = false;
    store.clearFilter();
    store.remoteFilter = true;
    Doesn't look really nice, but it works at the moment.
    Bruno Tavares, Solutions Engineer
    Sencha, Inc.

  6. #5
    Sencha Premium Member Wedgie's Avatar
    Join Date
    Jan 2009
    Location
    Melbourne, Australia
    Posts
    76
    Vote Rating
    0
    Answers
    1
    Wedgie is on a distinguished road

      0  

    Thumbs up


    Thanks Bruno
    store.filters.clear() works a treat