BufferedRenderer.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. Ext.define('saas.override.grid.buffer.BufferedRenderer', {
  2. override: 'Ext.grid.plugin.BufferedRenderer',
  3. setViewSize: function(viewSize, fromLockingPartner) {
  4. var me = this,
  5. store = me.store,
  6. view = me.view,
  7. ownerGrid,
  8. rows = view.all,
  9. elCount = rows.getCount(),
  10. storeCount = store.getCount(),
  11. start, end,
  12. lockingPartner = me.view.lockingPartner && me.view.lockingPartner.bufferedRenderer,
  13. diff = elCount - viewSize,
  14. oldTop = 0,
  15. maxIndex = Math.max(0, storeCount - 1),
  16. // This is which end is closer to being visible therefore must be the first to have rows added
  17. // or the opposite end from which rows get removed if shrinking the view.
  18. pointyEnd = Ext.Number.sign((me.getFirstVisibleRowIndex() - rows.startIndex) - (rows.endIndex - me.getLastVisibleRowIndex()));
  19. // Synchronize view sizes
  20. if (lockingPartner && !fromLockingPartner) {
  21. lockingPartner.setViewSize(viewSize, true);
  22. }
  23. diff = elCount - viewSize;
  24. if (diff) {
  25. // Must be set for getFirstVisibleRowIndex to work
  26. me.scrollTop = me.scroller ? me.scroller.getPosition().y : 0;
  27. me.viewSize = viewSize;
  28. if (store.isBufferedStore) {
  29. store.setViewSize(viewSize);
  30. }
  31. // If a store loads before we have calculated a viewSize, it loads me.defaultViewSize records.
  32. // This may be larger or smaller than the final viewSize so the store needs adjusting when the view size is calculated.
  33. if (elCount) {
  34. // New start index should be current start index unless that's now too close to the end of the store
  35. // to yield a full view, in which case work back from the end of the store.
  36. // Ensure we don't go negative.
  37. start = Math.max(0, Math.min(rows.startIndex, storeCount - viewSize));
  38. // New end index works forward from the new start index ensuring we don't walk off the end
  39. end = Math.min(start + viewSize - 1, maxIndex);
  40. // Only do expensive adding or removal if range is not already correct
  41. if (start === rows.startIndex && end === rows.endIndex) {
  42. // Needs rows adding to or bottom depending on which end is closest
  43. // to being visible (The pointy end)
  44. if (diff < 0) {
  45. me.handleViewScroll(pointyEnd);
  46. }
  47. } else {
  48. // While changing our visible range, the locking partner must not sync
  49. if (lockingPartner) {
  50. lockingPartner.disable();
  51. }
  52. // View must expand
  53. if (diff < 0) {
  54. // If it's *possible* to add rows...
  55. if (storeCount > viewSize && storeCount > elCount) {
  56. // Grab the render range with a view to appending and prepending
  57. // nodes to the top and bottom as necessary.
  58. // Store's getRange API always has been inclusive of endIndex.
  59. store.getRange(start, end, {
  60. callback: function(newRecords, start, end) {
  61. ownerGrid = view.ownerGrid;
  62. // Append if necessary
  63. if (end > rows.endIndex) {
  64. rows.scroll(Ext.Array.slice(newRecords, rows.endIndex + 1, Infinity), 1, 0);
  65. }
  66. // Prepend if necessary
  67. if (start < rows.startIndex) {
  68. oldTop = rows.first(true);
  69. rows.scroll(Ext.Array.slice(newRecords, 0, rows.startIndex - start), -1, 0);
  70. // We just added some rows to the top of the rendered block
  71. // We have to bump it up to keep the view stable.
  72. me.bodyTop -= oldTop.offsetTop;
  73. }
  74. me.setBodyTop(me.bodyTop);
  75. // The newly added rows must sync the row heights
  76. if (lockingPartner && !fromLockingPartner && (ownerGrid.syncRowHeight || ownerGrid.syncRowHeightOnNextLayout)) {
  77. lockingPartner.setViewSize(viewSize, true);
  78. ownerGrid.syncRowHeights();
  79. }
  80. }
  81. });
  82. } else // If not possible just refresh
  83. {
  84. me.refreshView(0);
  85. }
  86. } else // View size is contracting
  87. {
  88. // If removing from top, we have to bump the rendered block downwards
  89. // by the height of the removed rows.
  90. if (pointyEnd === 1) {
  91. oldTop = rows.item(rows.startIndex + diff, true).offsetTop;
  92. }
  93. // Clip the rows off the required end
  94. rows.clip(pointyEnd, diff);
  95. me.setBodyTop(me.bodyTop + oldTop);
  96. }
  97. if (lockingPartner) {
  98. lockingPartner.enable();
  99. }
  100. }
  101. }
  102. // Update scroll range
  103. me.refreshSize();
  104. }
  105. if(this.grid.xtype=='power-grid'){
  106. viewSize = 61
  107. }
  108. return viewSize;
  109. },
  110. });