3 var FrozenColumns =
function FrozenColumns(table) {
6 this.rightColumns = [];
10 this.initializationMode =
"left";
12 this.scrollEndTimer =
false;
16 FrozenColumns.prototype.reset =
function () {
17 this.initializationMode =
"left";
18 this.leftColumns = [];
19 this.rightColumns = [];
25 this.table.columnManager.headersElement.style.marginLeft = 0;
26 this.table.columnManager.element.style.paddingRight = 0;
30 FrozenColumns.prototype.initializeColumn =
function (column) {
31 var config = { margin: 0, edge:
false };
33 if (column.definition.frozen) {
35 if (!column.parent.isGroup) {
37 if (!column.isGroup) {
38 config.position = this.initializationMode;
40 if (this.initializationMode ==
"left") {
41 this.leftColumns.push(column);
43 this.rightColumns.unshift(column);
48 column.modules.frozen = config;
50 console.warn(
"Frozen Column Error - Column Groups cannot be frozen");
53 console.warn(
"Frozen Column Error - Grouped columns cannot be frozen");
56 this.initializationMode =
"right";
61 FrozenColumns.prototype.scrollHorizontal =
function () {
67 clearTimeout(this.scrollEndTimer);
70 this.scrollEndTimer = setTimeout(
function () {
74 rows = this.table.rowManager.getVisibleRows();
78 this.layoutColumnPosition();
80 this.layoutCalcRows();
82 rows.forEach(
function (row) {
83 if (row.type ===
"row") {
88 this.table.rowManager.tableElement.style.marginRight = this.rightMargin;
93 FrozenColumns.prototype.calcMargins =
function () {
94 this.leftMargin = this._calcSpace(this.leftColumns, this.leftColumns.length) +
"px";
95 this.table.columnManager.headersElement.style.marginLeft = this.leftMargin;
97 this.rightMargin = this._calcSpace(this.rightColumns, this.rightColumns.length) +
"px";
98 this.table.columnManager.element.style.paddingRight = this.rightMargin;
101 this.rightPadding = this.table.rowManager.element.clientWidth + this.table.columnManager.scrollLeft;
105 FrozenColumns.prototype.layoutCalcRows =
function () {
106 if (this.table.modExists(
"columnCalcs")) {
107 if (this.table.modules.columnCalcs.topInitialized &&
this.table.modules.columnCalcs.topRow) {
108 this.layoutRow(this.table.modules.columnCalcs.topRow);
110 if (this.table.modules.columnCalcs.botInitialized &&
this.table.modules.columnCalcs.botRow) {
111 this.layoutRow(this.table.modules.columnCalcs.botRow);
117 FrozenColumns.prototype.layoutColumnPosition =
function (allCells) {
120 this.leftColumns.forEach(
function (column, i) {
121 column.modules.frozen.margin = _this2._calcSpace(_this2.leftColumns, i) + _this2.table.columnManager.scrollLeft +
"px";
123 if (i == _this2.leftColumns.length - 1) {
124 column.modules.frozen.edge =
true;
126 column.modules.frozen.edge =
false;
129 _this2.layoutElement(column.getElement(), column);
132 column.cells.forEach(
function (cell) {
133 _this2.layoutElement(cell.getElement(), column);
138 this.rightColumns.forEach(
function (column, i) {
139 column.modules.frozen.margin = _this2.rightPadding - _this2._calcSpace(_this2.rightColumns, i + 1) +
"px";
141 if (i == _this2.rightColumns.length - 1) {
142 column.modules.frozen.edge =
true;
144 column.modules.frozen.edge =
false;
147 _this2.layoutElement(column.getElement(), column);
150 column.cells.forEach(
function (cell) {
151 _this2.layoutElement(cell.getElement(), column);
158 FrozenColumns.prototype.layout =
function () {
172 self.table.rowManager.getDisplayRows().forEach(
function (row) {
173 if (row.type ===
"row") {
179 this.layoutCalcRows();
182 this.layoutColumnPosition(
true);
188 this.table.rowManager.tableElement.style.marginRight = this.rightMargin;
192 FrozenColumns.prototype.layoutRow =
function (row) {
195 var rowEl = row.getElement();
197 rowEl.style.paddingLeft = this.leftMargin;
200 this.leftColumns.forEach(
function (column) {
201 var cell = row.getCell(column);
204 _this3.layoutElement(cell.getElement(), column);
208 this.rightColumns.forEach(
function (column) {
209 var cell = row.getCell(column);
212 _this3.layoutElement(cell.getElement(), column);
217 FrozenColumns.prototype.layoutElement =
function (element, column) {
219 if (column.modules.frozen) {
220 element.style.position =
"absolute";
221 element.style.left = column.modules.frozen.margin;
223 element.classList.add(
"tabulator-frozen");
225 if (column.modules.frozen.edge) {
226 element.classList.add(
"tabulator-frozen-" + column.modules.frozen.position);
231 FrozenColumns.prototype._calcSpace =
function (columns, index) {
234 for (var i = 0; i < index; i++) {
235 if (columns[i].visible) {
236 width += columns[i].getWidth();
243 Tabulator.prototype.registerModule(
"frozenColumns", FrozenColumns);