You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
3.7 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. /* Fix for Opera, which does not seem to include the map function on Array's */
  16. if (!Array.prototype.map) {
  17. Array.prototype.map = function(fun){
  18. var len = this.length;
  19. if (typeof fun != 'function') {
  20. throw new TypeError();
  21. }
  22. var res = new Array(len);
  23. var thisp = arguments[1];
  24. for (var i = 0; i < len; i++) {
  25. if (i in this) {
  26. res[i] = fun.call(thisp, this[i], i, this);
  27. }
  28. }
  29. return res;
  30. };
  31. }
  32. Ext.ns('Ext.ux.data');
  33. /**
  34. * @class Ext.ux.data.PagingMemoryProxy
  35. * @extends Ext.data.MemoryProxy
  36. * <p>Paging Memory Proxy, allows to use paging grid with in memory dataset</p>
  37. */
  38. Ext.ux.data.PagingMemoryProxy = Ext.extend(Ext.data.MemoryProxy, {
  39. constructor : function(data){
  40. Ext.ux.data.PagingMemoryProxy.superclass.constructor.call(this);
  41. this.data = data;
  42. },
  43. doRequest : function(action, rs, params, reader, callback, scope, options){
  44. params = params ||
  45. {};
  46. var result;
  47. try {
  48. result = reader.readRecords(this.data);
  49. }
  50. catch (e) {
  51. this.fireEvent('loadexception', this, options, null, e);
  52. callback.call(scope, null, options, false);
  53. return;
  54. }
  55. // filtering
  56. if (params.filter !== undefined) {
  57. result.records = result.records.filter(function(el){
  58. if (typeof(el) == 'object') {
  59. var att = params.filterCol || 0;
  60. return String(el.data[att]).match(params.filter) ? true : false;
  61. }
  62. else {
  63. return String(el).match(params.filter) ? true : false;
  64. }
  65. });
  66. result.totalRecords = result.records.length;
  67. }
  68. // sorting
  69. if (params.sort !== undefined) {
  70. // use integer as params.sort to specify column, since arrays are not named
  71. // params.sort=0; would also match a array without columns
  72. var dir = String(params.dir).toUpperCase() == 'DESC' ? -1 : 1;
  73. var fn = function(v1, v2){
  74. return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
  75. };
  76. result.records.sort(function(a, b){
  77. var v = 0;
  78. if (typeof(a) == 'object') {
  79. v = fn(a.data[params.sort], b.data[params.sort]) * dir;
  80. }
  81. else {
  82. v = fn(a, b) * dir;
  83. }
  84. if (v == 0) {
  85. v = (a.index < b.index ? -1 : 1);
  86. }
  87. return v;
  88. });
  89. }
  90. // paging (use undefined cause start can also be 0 (thus false))
  91. if (params.start !== undefined && params.limit !== undefined) {
  92. result.records = result.records.slice(params.start, params.start + params.limit);
  93. }
  94. callback.call(scope, result, options, true);
  95. }
  96. });
  97. //backwards compat.
  98. Ext.data.PagingMemoryProxy = Ext.ux.data.PagingMemoryProxy;