1. #11
    Ext User
    Join Date
    Apr 2007
    Location
    Alexandria, VA
    Posts
    12
    Vote Rating
    0
    suntoast is on a distinguished road

      0  

    Default


    Here is some code you can use for paging of a "MemoryProxy". I extended MemoryProxy to create a new class called BufferedMemoryProxy.

    The only difference between this and the MemoryProxy is the section:
    Code:
            if (params.limit && params.start != null) {
                result.records = result.records.slice(params.start, params.start + params.limit);
            }
    Hope it works for you

    Code:
    Ext.data.BufferedMemoryProxy = function(data){
        Ext.data.BufferedMemoryProxy.superclass.constructor.call(this);
        this.data = data;
    };
    
    Ext.extend(Ext.data.BufferedMemoryProxy, Ext.data.MemoryProxy, {
        
        load : function(params, reader, callback, scope, arg){
            params = params || {};
            var result;
            try {
                result = reader.readRecords(this.data);
            }catch(e){
                this.fireEvent("loadexception", this, arg, null, e);
                callback.call(scope, null, arg, false);
                return;
            }
            
            if (params.limit && params.start != null) {
                result.records = result.records.slice(params.start, params.start + params.limit);
            }
            callback.call(scope, result, arg, true);
        }
    });

  2. #12
    Ext User dxs's Avatar
    Join Date
    Apr 2007
    Posts
    3
    Vote Rating
    0
    dxs is on a distinguished road

      0  

    Exclamation paging toolbar?

    paging toolbar?


    Wow, this works great! but it doesn't seem to update the paging toolbar. I have used this extension to add in memory paging of datasets down to 20 rows per page. When loading 1000+ rows It correctly shows only the first 20 but the paging toolbar says page 1 of 1. When I manually type in page '2' and hit enter then the paging toolbar seems to "come alive" and correctly shows my second page of data. It also tells me that I now have 51 (in my case) pages of data. Is there some way to refresh the paging system to make this work as expected?

    Thanks in advance,
    David

  3. #13
    Sencha User trbs's Avatar
    Join Date
    Mar 2007
    Posts
    310
    Vote Rating
    0
    trbs is on a distinguished road

      0  

    Default


    suntoast; that looks exactly like my example for locales in Ext 1.0.
    For that i wrote up my own in memory paging proxy; guess there not many different ways to solve this, so we ended up with almost identical code

    Take a look at it in the Ext 1.0 release: Ext-1.0/examples/locale/multi-lang.html and js. This one is currently a undocumented example that includes what i called a PagingMemoryProxy and it does the same thing

    Hopefully i will have a full example of this with sorting and paging ready to be officially in the documentation for the 1.1 release if our benevolent dictator for life agrees to it

  4. #14
    Ext User
    Join Date
    Mar 2007
    Posts
    21
    Vote Rating
    0
    waterlowa is on a distinguished road

      0  

    Default


    Wow just checked out the multi-lang example and it's fantastic!! Can't wait to try it out.

    One question: can we implement "baseParams" to filter this local data set?

  5. #15
    Touch Premium Member
    Join Date
    Mar 2007
    Location
    Canada
    Posts
    17
    Vote Rating
    0
    jt is on a distinguished road

      0  

    Default


    I came across this thread yesterday and have been playing around with the PagingMemoryProxy and the filter and find that it does exactly what I need.

    Here my question: Is it possible to use the PagingMemoryProxy and also being able to filter on all the data in memory (not just the data displayed on the current page)?

    Thanks for any and all help.

  6. #16
    Ext User
    Join Date
    Mar 2007
    Posts
    21
    Vote Rating
    0
    waterlowa is on a distinguished road

      0  

    Default


    I tried the PagingMemoryProxy. It's cool. But I'm going back to HttpProxy()...

    Reason is I find the ds hard to manipulate, especially when adding new row or deleting rows.

    In particular, ds.reload() doesn't do anything. Maybe I missed something.

    I think you nailed it, sorting also only applies to the displayed data. Using HttpProxy does increase the load on the server in a way (call to the server on almost every click), but for now it's a more perfect solution to me than PagingMemoryProxy.

    Your thoughts?

  7. #17
    Sencha User trbs's Avatar
    Join Date
    Mar 2007
    Posts
    310
    Vote Rating
    0
    trbs is on a distinguished road

      0  

    Default


    Quote Originally Posted by jt View Post
    I came across this thread yesterday and have been playing around with the PagingMemoryProxy and the filter and find that it does exactly what I need.

    Here my question: Is it possible to use the PagingMemoryProxy and also being able to filter on all the data in memory (not just the data displayed on the current page)?

    Thanks for any and all help.
    Sure you can

    This code is from the top of my head and i havn't checked it!
    but i hope it'll get u started.

    Where u can use sorting and filtering in very much the same way as elsewhere.
    Only difference is that you'll be referencing columns of the array instead of names, most likely.

    Code:
    params = { filter: "foo", filterCol: 1, sort: 2 }
    will filter column 1 of the array with keyword "foo" and sort in default direction on column 2.


    Code:
    /* Paging Memory Proxy, allows to use paging grid with in memory dataset */
    Ext.data.PagingMemoryProxy = function(data) {
    	Ext.data.PagingMemoryProxy.superclass.constructor.call(this);
    	this.data = data;
    };
    
    Ext.extend(Ext.data.PagingMemoryProxy, Ext.data.MemoryProxy, {
    	load : function(params, reader, callback, scope, arg) {
    		params = params || {};
    		var result;
    		try {
    			result = reader.readRecords(this.data);
    		}catch(e){
    			this.fireEvent("loadexception", this, arg, null, e);
    			callback.call(scope, null, arg, false);
    			return;
    		}
    		// filtering
    		if (params.filter) {
    		    results.records = results.records.filter(function(el){
    			if (typeof(el)=="object"){
    			    var att = params.filterCol || 0;
    			    return String(el[att]).match(params.filter)?true:false;
    			} else {
    			    return String(el).match(params.filter)?true:false;
    			}
    		    });
    		}
    		// sorting
    		if (params.sort) {
    		    // use integer as params.sort to specify column, since arrays are not named
    		    // params.sort=0; would also match a array without columns
    		    var dir = String(params.dir).toUpperCase() == "DESC" ? -1 : 1;
            	    var fn = function(r1, r2){
    			return r1 < r2;
            	    };
    		    result.records.sort(function(a, b) {
    			var v = 0;
    			if (typeof(a)=="object"){
    			    v = fn(a[params.sort], b[params.sort]) * dir;
    			} else {
    			    v = fn(a, b) * dir;
    			}
    			if (v==0) {
    			    v = (a.index < b.index ? -1 : 1);
    			}
    			return v;
    		    });
    		}
    		// paging
    		if ( (params.start) && (params.limit) ) {
    			result.records = result.records.slice(params.start, params.start+params.limit);
    		}
    		callback.call(scope, result, arg, true);
    	}
    });
    Attached Files

  8. #18
    Touch Premium Member
    Join Date
    Mar 2007
    Location
    Canada
    Posts
    17
    Vote Rating
    0
    jt is on a distinguished road

      0  

    Default


    Thanks for the code. It worked nicely.

    I only needed to make a couple of minor changes, noted below:

    Removed the s from result:

    result.records = result.records.filter(function(el) {


    In the filter section:

    return String(el.data[att]).match(params.filter)?true:false;

    So I could filter based on a column name.


    In the sort section:

    v = fn(a.data[params.sort], b.data[params.sort]) * dir;

    So I could sort based on a column name.


    Pretty impressive for not being checked.


    Should the Number of pages be updated in the PagingToolbar with the results returned (i.e. If the filter returns 1 row should the page count be 1 of 1)?

    If the filtered results span multiple pages, how do I see the other pages? Once I click on the next arrow the display no longer uses the filter and just displays the original data.

    Thanks for the help.

  9. #19
    Sencha User trbs's Avatar
    Join Date
    Mar 2007
    Posts
    310
    Vote Rating
    0
    trbs is on a distinguished road

      0  

    Default


    yeah nice report, only a typo and common mistake (for me), not too bad

    Should the Number of pages be updated in the PagingToolbar with the results returned (i.e. If the filter returns 1 row should the page count be 1 of 1)?
    absolutly right; the filtering should modify the totalRecords attribute, at the end of filtering there should be this:
    result.totalRecords = result.records.length;

    If the filtered results span multiple pages, how do I see the other pages? Once I click on the next arrow the display no longer uses the filter and just displays the original data.
    Did you put the filtering parameters in store.baseParams ?
    baseParams will remember your filter settings, params given as a attributes to the load() method will not.
    or use store.on('beforeload') event as covered elsewhere in the forums
    Attached Files

  10. #20
    Touch Premium Member
    Join Date
    Mar 2007
    Location
    Canada
    Posts
    17
    Vote Rating
    0
    jt is on a distinguished road

      0  

    Thumbs up


    Thanks.

    These changes did it. It gave me what I wanted.

    I am now doing a 'beforeload' event and storing the filter in the baseParams. It works beautifully.

    I needed to make a change to the sort routine.

    I also needed to adjust to the paging from:
    Code:
    		// paging
    		if (params.start && params.limit) {
    to:
    Code:
    		// paging
    		if (params.start !== undefined && params.limit !== undefined) {
    This was needed because if params.start==0 then params.start is false.

    I have attached the js file with the changes.

    Thanks again.
    Attached Files

Similar Threads

  1. [SOLVED] Memory Leak in Paging Grid Example?
    By cobnet in forum Ext 2.x: Help & Discussion
    Replies: 7
    Last Post: 3 May 2007, 8:24 PM
  2. Grid DataModel keeps data in memory
    By tane in forum Ext 1.x: Help & Discussion
    Replies: 2
    Last Post: 24 Feb 2007, 12:38 PM
  3. How to call array-grid?
    By sailaja in forum Ext 1.x: Help & Discussion
    Replies: 3
    Last Post: 16 Jan 2007, 6:56 AM
  4. Array-Grid in YUI
    By sailaja in forum Ext 1.x: Help & Discussion
    Replies: 3
    Last Post: 10 Jan 2007, 3:18 AM
  5. Array Grid Example
    By qintnt in forum Ext 1.x: Help & Discussion
    Replies: 1
    Last Post: 4 Dec 2006, 5:06 AM

Thread Participants: 19

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..."