Built files from Bizgaze WebServer
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.

frozen_columns.js 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /* Tabulator v4.8.2 (c) Oliver Folkerd */
  2. var FrozenColumns = function FrozenColumns(table) {
  3. this.table = table; //hold Tabulator object
  4. this.leftColumns = [];
  5. this.rightColumns = [];
  6. this.leftMargin = 0;
  7. this.rightMargin = 0;
  8. this.rightPadding = 0;
  9. this.initializationMode = "left";
  10. this.active = false;
  11. this.scrollEndTimer = false;
  12. };
  13. //reset initial state
  14. FrozenColumns.prototype.reset = function () {
  15. this.initializationMode = "left";
  16. this.leftColumns = [];
  17. this.rightColumns = [];
  18. this.leftMargin = 0;
  19. this.rightMargin = 0;
  20. this.rightMargin = 0;
  21. this.active = false;
  22. this.table.columnManager.headersElement.style.marginLeft = 0;
  23. this.table.columnManager.element.style.paddingRight = 0;
  24. };
  25. //initialize specific column
  26. FrozenColumns.prototype.initializeColumn = function (column) {
  27. var config = { margin: 0, edge: false };
  28. if (!column.isGroup) {
  29. if (this.frozenCheck(column)) {
  30. config.position = this.initializationMode;
  31. if (this.initializationMode == "left") {
  32. this.leftColumns.push(column);
  33. } else {
  34. this.rightColumns.unshift(column);
  35. }
  36. this.active = true;
  37. column.modules.frozen = config;
  38. } else {
  39. this.initializationMode = "right";
  40. }
  41. }
  42. };
  43. FrozenColumns.prototype.frozenCheck = function (column) {
  44. var frozen = false;
  45. if (column.parent.isGroup && column.definition.frozen) {
  46. console.warn("Frozen Column Error - Parent column group must be frozen, not individual columns or sub column groups");
  47. }
  48. if (column.parent.isGroup) {
  49. return this.frozenCheck(column.parent);
  50. } else {
  51. return column.definition.frozen;
  52. }
  53. return frozen;
  54. };
  55. //quick layout to smooth horizontal scrolling
  56. FrozenColumns.prototype.scrollHorizontal = function () {
  57. var _this = this;
  58. var rows;
  59. if (this.active) {
  60. clearTimeout(this.scrollEndTimer);
  61. //layout all rows after scroll is complete
  62. this.scrollEndTimer = setTimeout(function () {
  63. _this.layout();
  64. }, 100);
  65. rows = this.table.rowManager.getVisibleRows();
  66. this.calcMargins();
  67. this.layoutColumnPosition();
  68. this.layoutCalcRows();
  69. rows.forEach(function (row) {
  70. if (row.type === "row") {
  71. _this.layoutRow(row);
  72. }
  73. });
  74. this.table.rowManager.tableElement.style.marginRight = this.rightMargin;
  75. }
  76. };
  77. //calculate margins for rows
  78. FrozenColumns.prototype.calcMargins = function () {
  79. this.leftMargin = this._calcSpace(this.leftColumns, this.leftColumns.length) + "px";
  80. this.table.columnManager.headersElement.style.marginLeft = this.leftMargin;
  81. this.rightMargin = this._calcSpace(this.rightColumns, this.rightColumns.length) + "px";
  82. this.table.columnManager.element.style.paddingRight = this.rightMargin;
  83. //calculate right frozen columns
  84. this.rightPadding = this.table.rowManager.element.clientWidth + this.table.columnManager.scrollLeft;
  85. };
  86. //layout calculation rows
  87. FrozenColumns.prototype.layoutCalcRows = function () {
  88. if (this.table.modExists("columnCalcs")) {
  89. if (this.table.modules.columnCalcs.topInitialized && this.table.modules.columnCalcs.topRow) {
  90. this.layoutRow(this.table.modules.columnCalcs.topRow);
  91. }
  92. if (this.table.modules.columnCalcs.botInitialized && this.table.modules.columnCalcs.botRow) {
  93. this.layoutRow(this.table.modules.columnCalcs.botRow);
  94. }
  95. }
  96. };
  97. //calculate column positions and layout headers
  98. FrozenColumns.prototype.layoutColumnPosition = function (allCells) {
  99. var _this2 = this;
  100. var leftParents = [];
  101. this.leftColumns.forEach(function (column, i) {
  102. column.modules.frozen.margin = _this2._calcSpace(_this2.leftColumns, i) + _this2.table.columnManager.scrollLeft + "px";
  103. if (i == _this2.leftColumns.length - 1) {
  104. column.modules.frozen.edge = true;
  105. } else {
  106. column.modules.frozen.edge = false;
  107. }
  108. if (column.parent.isGroup) {
  109. var parentEl = _this2.getColGroupParentElement(column);
  110. if (!leftParents.includes(parentEl)) {
  111. _this2.layoutElement(parentEl, column);
  112. leftParents.push(parentEl);
  113. }
  114. if (column.modules.frozen.edge) {
  115. parentEl.classList.add("tabulator-frozen-" + column.modules.frozen.position);
  116. }
  117. } else {
  118. _this2.layoutElement(column.getElement(), column);
  119. }
  120. if (allCells) {
  121. column.cells.forEach(function (cell) {
  122. _this2.layoutElement(cell.getElement(), column);
  123. });
  124. }
  125. });
  126. this.rightColumns.forEach(function (column, i) {
  127. column.modules.frozen.margin = _this2.rightPadding - _this2._calcSpace(_this2.rightColumns, i + 1) + "px";
  128. if (i == _this2.rightColumns.length - 1) {
  129. column.modules.frozen.edge = true;
  130. } else {
  131. column.modules.frozen.edge = false;
  132. }
  133. if (column.parent.isGroup) {
  134. _this2.layoutElement(_this2.getColGroupParentElement(column), column);
  135. } else {
  136. _this2.layoutElement(column.getElement(), column);
  137. }
  138. if (allCells) {
  139. column.cells.forEach(function (cell) {
  140. _this2.layoutElement(cell.getElement(), column);
  141. });
  142. }
  143. });
  144. };
  145. FrozenColumns.prototype.getColGroupParentElement = function (column) {
  146. return column.parent.isGroup ? this.getColGroupParentElement(column.parent) : column.getElement();
  147. };
  148. //layout columns appropropriatly
  149. FrozenColumns.prototype.layout = function () {
  150. var self = this,
  151. rightMargin = 0;
  152. if (self.active) {
  153. //calculate row padding
  154. this.calcMargins();
  155. // self.table.rowManager.activeRows.forEach(function(row){
  156. // self.layoutRow(row);
  157. // });
  158. // if(self.table.options.dataTree){
  159. self.table.rowManager.getDisplayRows().forEach(function (row) {
  160. if (row.type === "row") {
  161. self.layoutRow(row);
  162. }
  163. });
  164. // }
  165. this.layoutCalcRows();
  166. //calculate left columns
  167. this.layoutColumnPosition(true);
  168. // if(tableHolder.scrollHeight > tableHolder.clientHeight){
  169. // rightMargin -= tableHolder.offsetWidth - tableHolder.clientWidth;
  170. // }
  171. this.table.rowManager.tableElement.style.marginRight = this.rightMargin;
  172. }
  173. };
  174. FrozenColumns.prototype.layoutRow = function (row) {
  175. var _this3 = this;
  176. var rowEl = row.getElement();
  177. rowEl.style.paddingLeft = this.leftMargin;
  178. // rowEl.style.paddingRight = this.rightMargin + "px";
  179. this.leftColumns.forEach(function (column) {
  180. var cell = row.getCell(column);
  181. if (cell) {
  182. _this3.layoutElement(cell.getElement(), column);
  183. }
  184. });
  185. this.rightColumns.forEach(function (column) {
  186. var cell = row.getCell(column);
  187. if (cell) {
  188. _this3.layoutElement(cell.getElement(), column);
  189. }
  190. });
  191. };
  192. FrozenColumns.prototype.layoutElement = function (element, column) {
  193. if (column.modules.frozen) {
  194. element.style.position = "absolute";
  195. element.style.left = column.modules.frozen.margin;
  196. element.classList.add("tabulator-frozen");
  197. if (column.modules.frozen.edge) {
  198. element.classList.add("tabulator-frozen-" + column.modules.frozen.position);
  199. }
  200. }
  201. };
  202. FrozenColumns.prototype._calcSpace = function (columns, index) {
  203. var width = 0;
  204. for (var i = 0; i < index; i++) {
  205. if (columns[i].visible) {
  206. width += columns[i].getWidth();
  207. }
  208. }
  209. return width;
  210. };
  211. Tabulator.prototype.registerModule("frozenColumns", FrozenColumns);