1. #1
    Ext JS Premium Member jadrake75's Avatar
    Join Date
    Sep 2008
    Posts
    108
    Vote Rating
    4
    jadrake75 is on a distinguished road

      0  

    Default PagingToolbar + store with remote filtering

    PagingToolbar + store with remote filtering


    So I ran across something that I solved but I am not sure what I did was any more than a "hack" and I would be interested in knowing how others might solve it.
    • My REST based web services use ODATA seach/query formats. So resources are called with a $filter=xxxx where xxxx is the search criteria on the query string.
    • The search criteria is not driven from the GridPanel showing the results but other controls which create the search criteria (using my own Predicate object that can output a filter string). An example of a filter string might look like
      Code:
      "(countryRef eq 56 and (purchased ge datetimeoffset'2013-04-03T00:00:00-05:00'))"
      - this would find stamps with country reference foreign key 56 purchased on or later than april 3rd, 2012.
    • I have a store that extends Ext.data.Store and here is where things get odd...
    Ok so to perform this query I call load( ) on my store with options.params.$filter equal to a filter similiar to that above. This works great. When I added a paging toolbar, I noticed that going to new pages didn't have the $filter to send, so I simply added a local variable for the filter in the store and if it changes update it. If there is a cached filter but no filter in the options then add it. (this is pretty straight forward). But I found the paging toolbar was not getting reset between $filter changes. This led to some weird situtaions where I was on page 5 of a filter and then going to a query that resulted in 2 pages stated Page 5 of 2 etc.

    Ok so my changes to both the load( ) and loadPage( ) are below to make this all work.... but it feels kind of a hack and I would be interested in knowing any better ways to do this!

    Code:
        /**     
         * Override the load function to stash the $filter ODATA string if defined
         * in the last known filter for the store.
         *
         * @param {Object} [options] The option if defined.
         */
        load: function(options) {
            var filterChanged = false;
            if (options && options.params) {
                if (this.lastFilter !== options.params.$filter) {
                    this.lastFilter = options.params.$filter;
                    filterChanged = true;  // we have a new filter!
                }
            }
            options = Ext.apply({}, options);
            if (filterChanged) {
                // reset the paging because we have a changed filter
                options.params = Ext.apply({$skip: 0, page: 1}, options.params);
                this.loadPage(1, options);
                return;
            }
            var args = [options];
            this.callParent(args);
        },
      
        loadPage: function(page, options) {
            if (this.lastFilter !== undefined) {
                options = Ext.apply({}, options);
                if (typeof options.params === 'undefined' || (options.params && typeof options.params.$filter === 'undefined')) {
                   // ensure the $filter is added if not there
                    options = Ext.apply({params: {$filter: this.lastFilter}}, options);
                }
            }
            var args = [page, options];
            this.callParent(args);
        }
    So here is why this is a hack (IMHO)
    1. Controller gets request from user to change criteria (from search panel for example) and builds the $filter string and calls store.load() with the $filter in the options.params
    2. Load picks up the filter change, sets the lastFilter variable, resets the page number and offset and then calls loadPage( ).
    3. LoadPage ensure the filter is there (only for subsequent page changes) and then calls load() again! (internally in parent)
    4. load( ) now sees there is no filter change (it was already changed) and does the physical load
    My problem here is this is dual overloading of load( ). ie. it is using it to load as well as reset and then load. I mean it works and the result is what I want, but it seems kind of messed up. I believe the filters on the store have to correspond to values on the model right? I couldn't have a filter with property key $filter and a value = to the ODATA filter string right?

    Stamp Image Bursting Application
    see http://code.google.com/p/stamp-imagebursting/

  2. #2
    Ext JS Premium Member jadrake75's Avatar
    Join Date
    Sep 2008
    Posts
    108
    Vote Rating
    4
    jadrake75 is on a distinguished road

      0  

    Default


    Ok, I may have found a cleaner work-around using the filters afterall. What I did is:

    1. in my controller call
    Code:
    store.clearFilters(true);
    store.filter({property:'$filter', value: odata_string } );
    1. I made a small change in my proxy to handle the filter.
    (1) set the filterParam to '$filter'
    (2) overwrote encodeFilters to simply return the value of the filter set on the store. for example:

    Code:
    encodeFilters: function(filters) {
       var len = filters.length, i = 0;
       for (; i < len; i++) {
          if (filters[i].property === this.filterParam) {
             return filters[i].value;
          }
       }
       return '';
    }


    This seems a much cleaner less "hacky" solution (the only hack would be the filter override in the proxy but if I am always filtering with ODATA only and not other solutions this might work. If I want to locally filter the results (for example I get back all the results where country is X but I then want to allow the user to locally filter on results that are not part of the search but are a subset of the results) - is this even possible? Or have I prevented this now by using remote filtering?

    -Jason
    Stamp Image Bursting Application
    see http://code.google.com/p/stamp-imagebursting/

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi