3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.ux.data.PagingMemoryProxy
17 * @extends Ext.data.proxy.Memory
18 * <p>Paging Memory Proxy, allows to use paging grid with in memory dataset</p>
20 Ext.define('Ext.ux.data.PagingMemoryProxy', {
21 extend: 'Ext.data.proxy.Memory',
22 alias: 'proxy.pagingmemory',
23 alternateClassName: 'Ext.data.PagingMemoryProxy',
25 read : function(operation, callback, scope){
26 var reader = this.getReader(),
27 result = reader.read(this.data),
28 sorters, filters, sorterFn, records;
30 scope = scope || this;
32 filters = operation.filters;
33 if (filters.length > 0) {
34 //at this point we have an array of Ext.util.Filter objects to filter with,
35 //so here we construct a function that combines these filters by ANDing them together
38 Ext.each(result.records, function(record) {
40 length = filters.length,
43 for (i = 0; i < length; i++) {
44 var filter = filters[i],
48 isMatch = isMatch && fn.call(scope, record);
55 result.records = records;
56 result.totalRecords = result.total = records.length;
60 sorters = operation.sorters;
61 if (sorters.length > 0) {
62 //construct an amalgamated sorter function which combines all of the Sorters passed
63 sorterFn = function(r1, r2) {
64 var result = sorters[0].sort(r1, r2),
65 length = sorters.length,
68 //if we have more than one sorter, OR any additional sorter functions together
69 for (i = 1; i < length; i++) {
70 result = result || sorters[i].sort.call(this, r1, r2);
76 result.records.sort(sorterFn);
79 // paging (use undefined cause start can also be 0 (thus false))
80 if (operation.start !== undefined && operation.limit !== undefined) {
81 result.records = result.records.slice(operation.start, operation.start + operation.limit);
82 result.count = result.records.length;
85 Ext.apply(operation, {
89 operation.setCompleted();
90 operation.setSuccessful();
92 Ext.Function.defer(function () {
93 Ext.callback(callback, scope, [operation]);