PagingMemoryProxy.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-ux-data-PagingMemoryProxy'>/**
  19. </span> * @class Ext.ux.data.PagingMemoryProxy
  20. * @extends Ext.data.proxy.Memory
  21. * &lt;p&gt;Paging Memory Proxy, allows to use paging grid with in memory dataset&lt;/p&gt;
  22. */
  23. Ext.define('Ext.ux.data.PagingMemoryProxy', {
  24. extend: 'Ext.data.proxy.Memory',
  25. alias: 'proxy.pagingmemory',
  26. alternateClassName: 'Ext.data.PagingMemoryProxy',
  27. read : function(operation, callback, scope){
  28. var reader = this.getReader(),
  29. result = reader.read(this.data),
  30. sorters, filters, sorterFn, records;
  31. scope = scope || this;
  32. // filtering
  33. filters = operation.filters;
  34. if (filters.length &gt; 0) {
  35. //at this point we have an array of Ext.util.Filter objects to filter with,
  36. //so here we construct a function that combines these filters by ANDing them together
  37. records = [];
  38. Ext.each(result.records, function(record) {
  39. var isMatch = true,
  40. length = filters.length,
  41. i;
  42. for (i = 0; i &lt; length; i++) {
  43. var filter = filters[i],
  44. fn = filter.filterFn,
  45. scope = filter.scope;
  46. isMatch = isMatch &amp;&amp; fn.call(scope, record);
  47. }
  48. if (isMatch) {
  49. records.push(record);
  50. }
  51. }, this);
  52. result.records = records;
  53. result.totalRecords = result.total = records.length;
  54. }
  55. // sorting
  56. sorters = operation.sorters;
  57. if (sorters.length &gt; 0) {
  58. //construct an amalgamated sorter function which combines all of the Sorters passed
  59. sorterFn = function(r1, r2) {
  60. var result = sorters[0].sort(r1, r2),
  61. length = sorters.length,
  62. i;
  63. //if we have more than one sorter, OR any additional sorter functions together
  64. for (i = 1; i &lt; length; i++) {
  65. result = result || sorters[i].sort.call(this, r1, r2);
  66. }
  67. return result;
  68. };
  69. result.records.sort(sorterFn);
  70. }
  71. // paging (use undefined cause start can also be 0 (thus false))
  72. if (operation.start !== undefined &amp;&amp; operation.limit !== undefined) {
  73. result.records = result.records.slice(operation.start, operation.start + operation.limit);
  74. result.count = result.records.length;
  75. }
  76. Ext.apply(operation, {
  77. resultSet: result
  78. });
  79. operation.setCompleted();
  80. operation.setSuccessful();
  81. Ext.Function.defer(function () {
  82. Ext.callback(callback, scope, [operation]);
  83. }, 10);
  84. }
  85. });
  86. </pre>
  87. </body>
  88. </html>