]> git.proxmox.com Git - extjs.git/blame - extjs/packages/ux/classic/src/data/PagingMemoryProxy.js
add extjs 6.0.1 sources
[extjs.git] / extjs / packages / ux / classic / src / data / PagingMemoryProxy.js
CommitLineData
6527f429
DM
1/**\r
2 * Paging Memory Proxy, allows to use paging grid with in memory dataset\r
3 */\r
4Ext.define('Ext.ux.data.PagingMemoryProxy', {\r
5 extend: 'Ext.data.proxy.Memory',\r
6 alias: 'proxy.pagingmemory',\r
7 alternateClassName: 'Ext.data.PagingMemoryProxy',\r
8 \r
9 constructor: function() {\r
10 Ext.log.warn('Ext.ux.data.PagingMemoryProxy functionality has been merged into Ext.data.proxy.Memory by using the enablePaging flag.'); \r
11 this.callParent(arguments);\r
12 },\r
13\r
14 read : function(operation, callback, scope){\r
15 var reader = this.getReader(),\r
16 result = reader.read(this.data),\r
17 sorters, filters, sorterFn, records;\r
18\r
19 scope = scope || this;\r
20 // filtering\r
21 filters = operation.filters;\r
22 if (filters.length > 0) {\r
23 //at this point we have an array of Ext.util.Filter objects to filter with,\r
24 //so here we construct a function that combines these filters by ANDing them together\r
25 records = [];\r
26\r
27 Ext.each(result.records, function(record) {\r
28 var isMatch = true,\r
29 length = filters.length,\r
30 i;\r
31\r
32 for (i = 0; i < length; i++) {\r
33 var filter = filters[i],\r
34 fn = filter.filterFn,\r
35 scope = filter.scope;\r
36\r
37 isMatch = isMatch && fn.call(scope, record);\r
38 }\r
39 if (isMatch) {\r
40 records.push(record);\r
41 }\r
42 }, this);\r
43\r
44 result.records = records;\r
45 result.totalRecords = result.total = records.length;\r
46 }\r
47 \r
48 // sorting\r
49 sorters = operation.sorters;\r
50 if (sorters.length > 0) {\r
51 //construct an amalgamated sorter function which combines all of the Sorters passed\r
52 sorterFn = function(r1, r2) {\r
53 var result = sorters[0].sort(r1, r2),\r
54 length = sorters.length,\r
55 i;\r
56 \r
57 //if we have more than one sorter, OR any additional sorter functions together\r
58 for (i = 1; i < length; i++) {\r
59 result = result || sorters[i].sort.call(this, r1, r2);\r
60 } \r
61 \r
62 return result;\r
63 };\r
64 \r
65 result.records.sort(sorterFn);\r
66 }\r
67 \r
68 // paging (use undefined cause start can also be 0 (thus false))\r
69 if (operation.start !== undefined && operation.limit !== undefined) {\r
70 result.records = result.records.slice(operation.start, operation.start + operation.limit);\r
71 result.count = result.records.length;\r
72 }\r
73\r
74 Ext.apply(operation, {\r
75 resultSet: result\r
76 });\r
77 \r
78 operation.setCompleted();\r
79 operation.setSuccessful();\r
80\r
81 Ext.Function.defer(function () {\r
82 Ext.callback(callback, scope, [operation]);\r
83 }, 10);\r
84 }\r
85});\r