ui.pivot_grid.headers_area.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /**
  2. * DevExtreme (ui/pivot_grid/ui.pivot_grid.headers_area.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. var _renderer = require("../../core/renderer");
  11. var _renderer2 = _interopRequireDefault(_renderer);
  12. var _type = require("../../core/utils/type");
  13. var _array = require("../../core/utils/array");
  14. var _iterator = require("../../core/utils/iterator");
  15. var _uiPivot_grid = require("./ui.pivot_grid.area_item");
  16. function _interopRequireDefault(obj) {
  17. return obj && obj.__esModule ? obj : {
  18. "default": obj
  19. }
  20. }
  21. var PIVOTGRID_AREA_CLASS = "dx-pivotgrid-area";
  22. var PIVOTGRID_AREA_COLUMN_CLASS = "dx-pivotgrid-horizontal-headers";
  23. var PIVOTGRID_AREA_ROW_CLASS = "dx-pivotgrid-vertical-headers";
  24. var PIVOTGRID_TOTAL_CLASS = "dx-total";
  25. var PIVOTGRID_GRAND_TOTAL_CLASS = "dx-grandtotal";
  26. var PIVOTGRID_ROW_TOTAL_CLASS = "dx-row-total";
  27. var PIVOTGRID_EXPANDED_CLASS = "dx-pivotgrid-expanded";
  28. var PIVOTGRID_COLLAPSED_CLASS = "dx-pivotgrid-collapsed";
  29. var PIVOTGRID_LAST_CELL_CLASS = "dx-last-cell";
  30. var PIVOTGRID_VERTICAL_SCROLL_CLASS = "dx-vertical-scroll";
  31. var PIVOTGRID_EXPAND_BORDER = "dx-expand-border";
  32. function getCellPath(tableElement, cell) {
  33. if (cell) {
  34. var data = tableElement.data().data;
  35. var rowIndex = cell.parentNode.rowIndex;
  36. var cellIndex = cell.cellIndex;
  37. return data[rowIndex] && data[rowIndex][cellIndex] && data[rowIndex][cellIndex].path
  38. }
  39. }
  40. exports.HorizontalHeadersArea = _uiPivot_grid.AreaItem.inherit({
  41. _getAreaName: function() {
  42. return "column"
  43. },
  44. _getAreaClassName: function() {
  45. return PIVOTGRID_AREA_COLUMN_CLASS
  46. },
  47. _createGroupElement: function() {
  48. return (0, _renderer2.default)("<div>").addClass(this._getAreaClassName()).addClass(PIVOTGRID_AREA_CLASS)
  49. },
  50. _applyCustomStyles: function(options) {
  51. var cssArray = options.cssArray;
  52. var cell = options.cell;
  53. var rowsCount = options.rowsCount;
  54. var classArray = options.classArray;
  55. if (options.cellIndex === options.cellsCount - 1) {
  56. cssArray.push((options.rtlEnabled ? "border-left:" : "border-right:") + "0px")
  57. }
  58. if (cell.rowspan === rowsCount - options.rowIndex || options.rowIndex + 1 === rowsCount) {
  59. cssArray.push("border-bottom-width:0px")
  60. }
  61. if ("T" === cell.type || "GT" === cell.type) {
  62. classArray.push(PIVOTGRID_ROW_TOTAL_CLASS)
  63. }
  64. if ("T" === options.cell.type) {
  65. classArray.push(PIVOTGRID_TOTAL_CLASS)
  66. }
  67. if ("GT" === options.cell.type) {
  68. classArray.push(PIVOTGRID_GRAND_TOTAL_CLASS)
  69. }
  70. if ((0, _type.isDefined)(cell.expanded)) {
  71. classArray.push(cell.expanded ? PIVOTGRID_EXPANDED_CLASS : PIVOTGRID_COLLAPSED_CLASS)
  72. }
  73. this.callBase(options)
  74. },
  75. _getMainElementMarkup: function() {
  76. return "<thead class='" + this._getAreaClassName() + "'>"
  77. },
  78. _getCloseMainElementMarkup: function() {
  79. return "</thead>"
  80. },
  81. setVirtualContentParams: function(params) {
  82. this.callBase(params);
  83. this._setTableCss({
  84. left: params.left,
  85. top: 0
  86. });
  87. this._virtualContentWidth = params.width
  88. },
  89. hasScroll: function() {
  90. var tableWidth = this._virtualContent ? this._virtualContentWidth : this._tableWidth;
  91. if (this._groupWidth && tableWidth) {
  92. return tableWidth - this._groupWidth >= 1
  93. }
  94. return false
  95. },
  96. processScroll: function() {
  97. if (!this._getScrollable()) {
  98. this._groupElement.dxScrollable({
  99. useNative: false,
  100. useSimulatedScrollbar: false,
  101. showScrollbar: false,
  102. bounceEnabled: false,
  103. direction: "horizontal",
  104. updateManually: true
  105. })
  106. }
  107. },
  108. processScrollBarSpacing: function(scrollBarWidth) {
  109. var that = this;
  110. var groupAlignment = that.option("rtlEnabled") ? "right" : "left";
  111. if (that._groupWidth) {
  112. that.groupWidth(that._groupWidth - scrollBarWidth)
  113. }
  114. if (that._scrollBarWidth) {
  115. that._groupElement.next().remove()
  116. }
  117. that._groupElement.toggleClass(PIVOTGRID_VERTICAL_SCROLL_CLASS, scrollBarWidth > 0);
  118. that._groupElement.css("float", groupAlignment).width(that._groupHeight);
  119. that._scrollBarWidth = scrollBarWidth
  120. },
  121. ctor: function(component) {
  122. this.callBase(component);
  123. this._scrollBarWidth = 0
  124. },
  125. getScrollPath: function(offset) {
  126. var tableElement = this.tableElement();
  127. var cell;
  128. offset -= parseInt(tableElement[0].style.left, 10) || 0;
  129. (0, _iterator.each)(tableElement.find("td"), function(_, td) {
  130. if (1 === td.colSpan && td.offsetLeft <= offset && td.offsetWidth + td.offsetLeft > offset) {
  131. cell = td;
  132. return false
  133. }
  134. });
  135. return getCellPath(tableElement, cell)
  136. },
  137. _moveFakeTable: function(scrollPos) {
  138. this._moveFakeTableHorizontally(scrollPos);
  139. this.callBase()
  140. }
  141. });
  142. exports.VerticalHeadersArea = exports.HorizontalHeadersArea.inherit({
  143. _getAreaClassName: function() {
  144. return PIVOTGRID_AREA_ROW_CLASS
  145. },
  146. _applyCustomStyles: function(options) {
  147. this.callBase(options);
  148. if (options.cellIndex === options.cellsCount - 1) {
  149. options.classArray.push(PIVOTGRID_LAST_CELL_CLASS)
  150. }
  151. if (options.rowIndex === options.rowsCount - 1) {
  152. options.cssArray.push("border-bottom: 0px")
  153. }
  154. if (options.cell.isWhiteSpace) {
  155. options.classArray.push("dx-white-space-column")
  156. }
  157. },
  158. _getAreaName: function() {
  159. return "row"
  160. },
  161. setVirtualContentParams: function(params) {
  162. this.callBase(params);
  163. this._setTableCss({
  164. top: params.top,
  165. left: 0
  166. });
  167. this._virtualContentHeight = params.height
  168. },
  169. hasScroll: function() {
  170. var tableHeight = this._virtualContent ? this._virtualContentHeight : this._tableHeight;
  171. if (this._groupHeight && tableHeight) {
  172. return tableHeight - this._groupHeight >= 1
  173. }
  174. return false
  175. },
  176. processScroll: function() {
  177. if (!this._getScrollable()) {
  178. this._groupElement.dxScrollable({
  179. useNative: false,
  180. useSimulatedScrollbar: false,
  181. showScrollbar: false,
  182. bounceEnabled: false,
  183. direction: "vertical",
  184. updateManually: true
  185. })
  186. }
  187. },
  188. processScrollBarSpacing: function(scrollBarWidth) {
  189. var that = this;
  190. if (that._groupHeight) {
  191. that.groupHeight(that._groupHeight - scrollBarWidth)
  192. }
  193. if (that._scrollBarWidth) {
  194. that._groupElement.next().remove()
  195. }
  196. if (scrollBarWidth) {
  197. that._groupElement.after((0, _renderer2.default)("<div>").width("100%").height(scrollBarWidth - 1))
  198. }
  199. that._scrollBarWidth = scrollBarWidth
  200. },
  201. getScrollPath: function(offset) {
  202. var tableElement = this.tableElement();
  203. var cell;
  204. offset -= parseInt(tableElement[0].style.top, 10) || 0;
  205. (0, _iterator.each)(tableElement.find("tr"), function(_, tr) {
  206. var td = tr.childNodes[tr.childNodes.length - 1];
  207. if (td && 1 === td.rowSpan && td.offsetTop <= offset && td.offsetHeight + td.offsetTop > offset) {
  208. cell = td;
  209. return false
  210. }
  211. });
  212. return getCellPath(tableElement, cell)
  213. },
  214. _moveFakeTable: function(scrollPos) {
  215. this._moveFakeTableTop(scrollPos);
  216. this.callBase()
  217. },
  218. _getRowClassNames: function(rowIndex, cell, rowClassNames) {
  219. if (0 !== rowIndex & cell.expanded && (0, _array.inArray)(PIVOTGRID_EXPAND_BORDER, rowClassNames) === -1) {
  220. rowClassNames.push(PIVOTGRID_EXPAND_BORDER)
  221. }
  222. },
  223. _getMainElementMarkup: function() {
  224. return "<tbody class='" + this._getAreaClassName() + "'>"
  225. },
  226. _getCloseMainElementMarkup: function() {
  227. return "</tbody>"
  228. },
  229. updateColspans: function(columnCount) {
  230. var rows = this.tableElement()[0].rows;
  231. var columnOffset = 0;
  232. var columnOffsetResetIndexes = [];
  233. if (this.getColumnsCount() - columnCount > 0) {
  234. return
  235. }
  236. for (var i = 0; i < rows.length; i++) {
  237. for (var j = 0; j < rows[i].cells.length; j++) {
  238. var cell = rows[i].cells[j];
  239. var rowSpan = cell.rowSpan;
  240. if (columnOffsetResetIndexes[i]) {
  241. columnOffset -= columnOffsetResetIndexes[i];
  242. columnOffsetResetIndexes[i] = 0
  243. }
  244. var diff = columnCount - (columnOffset + cell.colSpan);
  245. if (j === rows[i].cells.length - 1 && diff > 0) {
  246. cell.colSpan = cell.colSpan + diff
  247. }
  248. columnOffsetResetIndexes[i + rowSpan] = (columnOffsetResetIndexes[i + rowSpan] || 0) + cell.colSpan;
  249. columnOffset += cell.colSpan
  250. }
  251. }
  252. }
  253. });