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.

96 lines
3.1 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * Ext JS Library 3.3.1
  3. * Copyright(c) 2006-2010 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. /* Fix for Opera, which does not seem to include the map function on Array's */
  8. if (!Array.prototype.map) {
  9. Array.prototype.map = function(fun){
  10. var len = this.length;
  11. if (typeof fun != 'function') {
  12. throw new TypeError();
  13. }
  14. var res = new Array(len);
  15. var thisp = arguments[1];
  16. for (var i = 0; i < len; i++) {
  17. if (i in this) {
  18. res[i] = fun.call(thisp, this[i], i, this);
  19. }
  20. }
  21. return res;
  22. };
  23. }
  24. Ext.ns('Ext.ux.data');
  25. /**
  26. * @class Ext.ux.data.PagingMemoryProxy
  27. * @extends Ext.data.MemoryProxy
  28. * <p>Paging Memory Proxy, allows to use paging grid with in memory dataset</p>
  29. */
  30. Ext.ux.data.PagingMemoryProxy = Ext.extend(Ext.data.MemoryProxy, {
  31. constructor : function(data){
  32. Ext.ux.data.PagingMemoryProxy.superclass.constructor.call(this);
  33. this.data = data;
  34. },
  35. doRequest : function(action, rs, params, reader, callback, scope, options){
  36. params = params ||
  37. {};
  38. var result;
  39. try {
  40. result = reader.readRecords(this.data);
  41. }
  42. catch (e) {
  43. this.fireEvent('loadexception', this, options, null, e);
  44. callback.call(scope, null, options, false);
  45. return;
  46. }
  47. // filtering
  48. if (params.filter !== undefined) {
  49. result.records = result.records.filter(function(el){
  50. if (typeof(el) == 'object') {
  51. var att = params.filterCol || 0;
  52. return String(el.data[att]).match(params.filter) ? true : false;
  53. }
  54. else {
  55. return String(el).match(params.filter) ? true : false;
  56. }
  57. });
  58. result.totalRecords = result.records.length;
  59. }
  60. // sorting
  61. if (params.sort !== undefined) {
  62. // use integer as params.sort to specify column, since arrays are not named
  63. // params.sort=0; would also match a array without columns
  64. var dir = String(params.dir).toUpperCase() == 'DESC' ? -1 : 1;
  65. var fn = function(v1, v2){
  66. return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
  67. };
  68. result.records.sort(function(a, b){
  69. var v = 0;
  70. if (typeof(a) == 'object') {
  71. v = fn(a.data[params.sort], b.data[params.sort]) * dir;
  72. }
  73. else {
  74. v = fn(a, b) * dir;
  75. }
  76. if (v == 0) {
  77. v = (a.index < b.index ? -1 : 1);
  78. }
  79. return v;
  80. });
  81. }
  82. // paging (use undefined cause start can also be 0 (thus false))
  83. if (params.start !== undefined && params.limit !== undefined) {
  84. result.records = result.records.slice(params.start, params.start + params.limit);
  85. }
  86. callback.call(scope, result, options, true);
  87. }
  88. });
  89. //backwards compat.
  90. Ext.data.PagingMemoryProxy = Ext.ux.data.PagingMemoryProxy;