Search code examples
extjsfilterextjs4storeextjs4.1

Filter store on server side in extjs4.1


I have to filter a grid store from a set of textfield/combobox inserted in the top of the page in a separated Ext.form.Panel. I use this code for do the grid filter:

doGridFilters : function() {
        //storeClients.clearFilter();
        var client_Id = Ext.getCmp('Id_form').getValue();
        var filter1 = Ext.create('Ext.util.Filter',{
             root:'list',
             comparison: 'eq',
             property: "Id",
             value: client_Id
        });

        storeClients.getProxy().extraParams = { filter: filter1 };
        storeClients.load();
    },

but the store don't perform any type of filter.

Can anyone help me?


Solution

  • Remotefiltering is quite easy:

    • The store must be configured with remoteFilter so that the proxy will handle and pass all applied filter
    • Next apply a filter with store.filter('propertyName', 'filtervalue'). The store will now automaticly loading after a filter get applied.
    • Expect a a list of filters at the serverside which looks like ...filter:[{property:'Name', value:'value'}]...

    And that's all. The remoteFilter property can be changed each time before applying a filter. For your case:

    doGridFilters : function(grid) {
        var store = grid.store;
        store.clearFilter();
        store.remoteFilter = true;// optional
        var client_Id = Ext.getCmp('Id_form').getValue();
        store.on('load', function(s){ s.remoteFilter = false; }, this, { single: true }) // optional
        store.filter("Id",client_Id);
    }
    

    Note: The proxy will always only apply the property-value paired filter, nothing more [ExtJS 4.1.1] For more you will need to override the responsible proxy function