3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
8 /* Fix for Opera, which does not seem to include the map function on Array's */
9 if (!Array.prototype.map) {
10 Array.prototype.map = function(fun){
11 var len = this.length;
12 if (typeof fun != 'function') {
13 throw new TypeError();
15 var res = new Array(len);
16 var thisp = arguments[1];
17 for (var i = 0; i < len; i++) {
19 res[i] = fun.call(thisp, this[i], i, this);
26 Ext.ns('Ext.ux.data');
29 * @class Ext.ux.data.PagingMemoryProxy
30 * @extends Ext.data.MemoryProxy
31 * <p>Paging Memory Proxy, allows to use paging grid with in memory dataset</p>
33 Ext.ux.data.PagingMemoryProxy = Ext.extend(Ext.data.MemoryProxy, {
34 constructor : function(data){
35 Ext.ux.data.PagingMemoryProxy.superclass.constructor.call(this);
38 doRequest : function(action, rs, params, reader, callback, scope, options){
43 result = reader.readRecords(this.data);
46 this.fireEvent('loadexception', this, options, null, e);
47 callback.call(scope, null, options, false);
52 if (params.filter !== undefined) {
53 result.records = result.records.filter(function(el){
54 if (typeof(el) == 'object') {
55 var att = params.filterCol || 0;
56 return String(el.data[att]).match(params.filter) ? true : false;
59 return String(el).match(params.filter) ? true : false;
62 result.totalRecords = result.records.length;
66 if (params.sort !== undefined) {
67 // use integer as params.sort to specify column, since arrays are not named
68 // params.sort=0; would also match a array without columns
69 var dir = String(params.dir).toUpperCase() == 'DESC' ? -1 : 1;
70 var fn = function(v1, v2){
71 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
73 result.records.sort(function(a, b){
75 if (typeof(a) == 'object') {
76 v = fn(a.data[params.sort], b.data[params.sort]) * dir;
82 v = (a.index < b.index ? -1 : 1);
87 // paging (use undefined cause start can also be 0 (thus false))
88 if (params.start !== undefined && params.limit !== undefined) {
89 result.records = result.records.slice(params.start, params.start + params.limit);
91 callback.call(scope, result, options, true);
96 Ext.data.PagingMemoryProxy = Ext.ux.data.PagingMemoryProxy;